package kr.co.pension.usr.pe.re.controller;

import java.awt.Image;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.ImageIcon;

import kr.co.pension.admin.co.ma.service.COMAService;
import kr.co.pension.admin.co.ma.vo.COMAVo;
import kr.co.pension.admin.pe.ti.service.PETIService;
import kr.co.pension.admin.pe.ti.vo.PETIVo;
import kr.co.pension.usr.pe.re.service.PEREService;
import kr.co.pension.usr.pe.re.vo.PEREVo;
import kr.co.pension.utils.AESSecurity;
import kr.co.pension.utils.BaseController;
import kr.co.pension.utils.JspUtil;
import kr.co.pension.utils.PaginationInfo;
import kr.co.pension.utils.SMCommonUtil;
import kr.co.pension.utils.sms.SMSUtil;

import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * 펜션 예약관리
 * 
 * @author devhw
 * 
 */
@Controller
@RequestMapping("/usr/pe/re/*")
public class PEREController extends BaseController {
	@Autowired
	private PEREService service;

	@Autowired
	private PETIService petiService;

	@Autowired
	private COMAService comaService;

	Logger log = Logger.getLogger(getClass());

	/**
	 * 펜션 예약화면
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere100Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));

		// 이전달 조회 금지
		if (chkMonth > chkConditionMonth) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		reservation_use_month = reservation_use_month - 1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt(frmDate1.format(maxMonthChk
				.getTime().getTime()));
		if (chkConditionMonth > maxMonthNum) {
			vo.setReservation_dt(maxMonthNum + "01");
			chkConditionMonth = maxMonthNum;
			mav.addObject("msg", (reservation_use_month + 1)
					+ "개월 이상은 예약이 불가능합니다.");
		}

		mav.addObject("reservation_dt", vo.getReservation_dt());

		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");

		// 객실 정보
		List list = service.pere101Q(vo);

		// 요금 정보 및 예약정보
		ModelAndView retMv1 = pere200_2Q(vo, req, res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();

		// 달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek = 0;
		int addDate = 0;

		// 일반달력일때

		if ("D".equals(pensionInfo.get("reservation_cal"))
				|| chkMonth != chkConditionMonth) {
			int year = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
			int month = Integer
					.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
			int date = 1;

			Calendar cal = Calendar.getInstance();
			cal.set(year, month, date);
			// 지금 요일
			int day1_7 = cal.get(Calendar.DAY_OF_WEEK);

			// 지금 몇번째 주
			int nowWeek = cal.get(Calendar.DAY_OF_MONTH);

			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

			// 이번달 몇번째주
			sMonthWeek = cal.get(Calendar.WEEK_OF_MONTH);

			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

			cal.get(Calendar.WEEK_OF_YEAR);

			int LastDate = cal.getActualMaximum(Calendar.DATE);

			addDate = (day1_7 + 6) - 7;

			drawCal.set(year, month, date);
			drawCal.add(Calendar.DATE, -addDate);
			textCal.append("<tr class=\"tt\" align=\"center\">");
			for (int i = 0; i < addDate; i++) {
				String yyymmdd = frmDate.format(drawCal.getTime().getTime());
				String dd = frmDateDD.format(drawCal.getTime().getTime());
				textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
				drawCal.add(Calendar.DATE, 1);
			}
		} else {
			// 이월달력일때
			Calendar cal = Calendar.getInstance();

			// 지금 요일
			int day1_7 = cal.get(Calendar.DAY_OF_WEEK);

			// 지금 몇번째 주
			int nowWeek = cal.get(Calendar.DAY_OF_MONTH);

			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

			// 이번달 몇번째주
			sMonthWeek = cal.get(Calendar.WEEK_OF_MONTH);

			cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

			cal.get(Calendar.WEEK_OF_YEAR);

			int LastDate = cal.getActualMaximum(Calendar.DATE);

			addDate = (day1_7 + 6) - 7;

			// Calendar drawCal = Calendar.getInstance();
			drawCal.add(Calendar.DATE, -addDate);
			textCal.append("<tr class=\"tt\" align=\"center\">");
			for (int i = 0; i < addDate; i++) {
				String yyymmdd = frmDate.format(drawCal.getTime().getTime());
				String dd = frmDateDD.format(drawCal.getTime().getTime());
				textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
				drawCal.add(Calendar.DATE, 1);
			}

			drawCal = Calendar.getInstance();
		}

		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for (int i = 1; i < 200; i++) {
			// 초기화
			tdHtml.setLength(0);
			int startDate = addDate + i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if (0 != i && "1".equals(dd)) {
				dd = Integer
						.toString(Integer.parseInt(yyymmdd.substring(4, 6)))
						+ "." + dd;
			}
			String gl_busy_type = "";
			String gl_pm_dc = "";
			String gl_pm_dc_style = "";

			// if("20120622".equals(yyymmdd)){
			// System.out.println("test");
			// }

			if (Integer.parseInt(frmDate.format(d1.getTime().getTime()))
					- Integer.parseInt(frmDate.format(drawCal.getTime()
							.getTime())) > 0) {

				tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\"#fdfdf6\"");
				tdHtml.append("	id=\"day_" + yyymmdd + "\">");
				tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
				tdHtml.append("		<tbody>");
				tdHtml.append("			<tr>");
				tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
				tdHtml.append("					<font color=\"green\">" + dd
						+ "</font></a></b>");
				tdHtml.append("					<span class=\"pm_nm pms\"></span>");
				tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;\"></span>");
				textCal.append(tdHtml.toString());
				textCal.append("				</td>");
				textCal.append("			</tr>");
				textCal.append("		</tbody>");
				textCal.append("	</table>");
				textCal.append("</td>");

				if (startDate % 7 == 0) {
					textCal.append("</tr>");
					if (sMonthWeek == chkWeek) {
						break;
					}
					textCal.append("<tr class=\"tt\" align=\"center\">");
					chkWeek++;
				}
				drawCal.add(Calendar.DATE, 1);

				continue;
			}
			String nowBgColor = "@bgcolor";
			if (Integer.parseInt(frmDate.format(d1.getTime().getTime()))
					- Integer.parseInt(frmDate.format(drawCal.getTime()
							.getTime())) == 0) {
				nowBgColor = "#e3fefe";
			}

			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""
					+ nowBgColor + "\"");
			tdHtml.append("	id=\"day_" + yyymmdd + "\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">" + dd
					+ "</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");

			String for_busy_type = "";
			int reservation_cnt = 0; // 예약수
			for (int j = 0; j < list.size(); j++) {

				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");

				int busy_1_base = (Integer) room.get("busy_1_base");
				int busy_1_fri = (Integer) room.get("busy_1_fri");
				int busy_1_sat = (Integer) room.get("busy_1_sat");

				roomsList.setLength(0);

				for (int k = readFast; k < list2.size(); k++) {
					// k=readFast;
					Map dateList = (Map) list2.get(k);

					String reservation_dt = dateList.get("reservation_dt") == null ? ""
							: (String) dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");

					if (Integer.parseInt(yyymmdd) < Integer
							.parseInt(reservation_dt)) {

						readFast = k - list.size();
						if (readFast < 0) {
							readFast = 0;
						}
						break;
					}
					if (reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no) {
						String busy_type = (String) dateList.get("busy_type") == null ? ""
								: (String) dateList.get("busy_type");
						for_busy_type = busy_type;
						String rm_status = (String) dateList.get("rm_status") == null ? ""
								: (String) dateList.get("rm_status");
						String reservation_nm = (String) dateList
								.get("reservation_nm") == null ? ""
								: (String) dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1") == null ? ""
								: (String) dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2") == null ? ""
								: (String) dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3") == null ? ""
								: (String) dateList.get("r_phone3");
						int pm_dc_m = dateList.get("pm_dc_m") == null ? 0
								: (Integer) dateList.get("pm_dc_m");
						int pm_per = dateList.get("pm_per") == null ? 0
								: (Integer) dateList.get("pm_per");

						String pm_pay = dateList.get("pm_pay") == null ? ""
								: String.valueOf(dateList.get("pm_pay"));
						gl_pm_dc_style = "margin-top:-10px;";
						if ("".equals(gl_pm_dc)) {
							// if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
							// if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
							// gl_pm_dc+="<br/>";
							// }
							// }
							gl_pm_dc += "<br/>";
							if (!"".equals(pm_pay)
									&& "Y".equals(pensionInfo.get("pm_dc_yn"))) {
								if (pm_dc_m > 0) {
									gl_pm_dc += "(" + "DC : " + pm_dc_m
											+ "원할인)";
								}
								if (pm_per > 0) {
									gl_pm_dc += "(" + "DC : " + pm_per
											+ "% 할인)";
								}
							}
						}

						if ("0101".equals(busy_type)) {
							gl_busy_type = "비수기 주중";
						} else if ("0102".equals(busy_type)) {
							gl_busy_type = "비수기 금요일";
						} else if ("0103".equals(busy_type)) {
							gl_busy_type = "비수기 토요일";
						} else if ("0104".equals(busy_type)) {
							gl_busy_type = "준수기 주중";
						} else if ("0105".equals(busy_type)) {
							gl_busy_type = "준수기 금요일";
						} else if ("0106".equals(busy_type)) {
							gl_busy_type = "준수기 토요일";
						} else if ("0107".equals(busy_type)) {
							gl_busy_type = "성수기 주중";
						} else if ("0108".equals(busy_type)) {
							gl_busy_type = "성수기 금요일";
						} else if ("0109".equals(busy_type)) {
							gl_busy_type = "성수기 토요일";
						} else if ("0110".equals(busy_type)) {
							gl_busy_type = "휴일";
						} else {

							if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
								gl_busy_type = "비수기 토요일";
								busy_type = "0103";
							} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn) // 금요일 사용 함일경우
							) {// 금요일
								gl_busy_type = "비수기 금요일";
								busy_type = "0102";
							} else {// 평일
								gl_busy_type = "비수기 주중";
								busy_type = "0101";
							}
						}
						if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
							gl_busy_type = "";
						}

						if ("0110".equals(busy_type)) {
							roomsList.append(" ");
						} else {
							roomsList
									.append("					<span	class=\"divDel\"><br/>");
							if ("Y".equals(p_ico_yn)) {
								if ("F".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								} else if ("C".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								} else if ("B".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}
							}
							String viewNm = room_nm;
							if ("C".equals(rm_status)) {
								viewNm = "<span class=\"ptrend\">예약완료</span>";
								reservation_cnt++;
							} else if ("R".equals(rm_status)) {
								viewNm = "<span class=\"ptrstandby\">예약대기</span>";
								reservation_cnt++;
							}
							String r_phone = "";
							if (null != r_phone1 && !"".equals(r_phone1)) {
								r_phone = r_phone1 + "-" + r_phone2 + "-"
										+ r_phone3;
							}

							roomsList
									.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
							roomsList
									.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
							roomsList
									.append("							onmouseout=\"hideTip()\"> ");
							roomsList.append("							<a href=\"#\" id=\"a_"
									+ pr_no + "_" + yyymmdd + "\"");
							roomsList
									.append("								onclick=\"goReserrvation('"
											+ p_id
											+ "',this,'"
											+ pr_no
											+ "');\" room_nm=\" "
											+ room_nm
											+ "\"");
							roomsList.append("								room_form=\"" + room_form
									+ "\" room_type=\"" + room_type
									+ "\" rm_status=\"" + rm_status
									+ "\" date=\"" + yyymmdd + "\"");
							roomsList.append("								busy_1_base=\""
									+ busy_1_base + "\" busy_1_fri=\""
									+ busy_1_fri + "\" busy_1_sat=\""
									+ busy_1_sat + "\" ");
							if (!"".equals(reservation_nm)) {
								roomsList.append("								reservation_nm=\""
										+ reservation_nm + "\" r_phone=\""
										+ r_phone + "\" ");
							}

							if (!"".equals(pm_pay)) {
								roomsList.append("						pm_pay=\"" + pm_pay
										+ "\"");
							}

							roomsList.append("								busy_type=\"" + busy_type
									+ "\"> " + viewNm + "</a>");
							roomsList.append("						</span>");
							roomsList.append("					</span>");
						}

					}
				}
				// 설정 안되어있을경우 기본으로 설정합
				if ("".equals(roomsList.toString())) {
					// 요금 설정해야함.
					String busy_type = "";

					if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
						gl_busy_type = "비수기 토요일";
						busy_type = "0103";
					} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn) // 금요일 사용 함일경우
					) {// 금요일
						gl_busy_type = "비수기 금요일";
						busy_type = "0102";
					} else {// 평일
						gl_busy_type = "비수기 주중";
						busy_type = "0101";
					}
					if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
						gl_busy_type = "";
					}

					// 기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if ("Y".equals(p_ico_yn)) {
						if ("F".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("C".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("B".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList
							.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList
							.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_" + pr_no
							+ "_" + yyymmdd + "\"");
					roomsList.append("								onclick=\"goReserrvation('"
							+ p_id + "',this,'" + pr_no + "');\" room_nm=\" "
							+ room_nm + "\"");
					roomsList.append("								room_form=\"" + room_form
							+ "\" room_type=\"" + room_type
							+ "\" rm_status=\"\" date=\"" + yyymmdd + "\"");
					roomsList.append("								busy_1_base=\"" + busy_1_base
							+ "\" busy_1_fri=\"" + busy_1_fri
							+ "\" busy_1_sat=\"" + busy_1_sat + "\" ");
					roomsList.append("								busy_type=\"" + busy_type
							+ "\"> " + room_nm + "</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				} else {

				}
				// 휴일일 경우 객실정보 입력안함
				if (!"0110".equals(for_busy_type)) {
					tdHtml.append(roomsList.toString());
				}
				// tdHtml.append(roomsList.toString());
			}
			// 휴일일경우 이미지로 대체
			if ("0110".equals(for_busy_type)) {
				tdHtml.append("<br/><table style=\"width:100%;height:100%;text-align: center\"><tr><td valign='middle'><img src=\"/usr/images/reservation.jpg\" border=\"0\" style=\"\"/></td></tr></table>");
			}

			// 색지정
			if (reservation_cnt == 0) {// 예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));

			} else if (reservation_cnt == list.size()) {// 예약 모두 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			} else {// 예약 조금 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");

			if (startDate % 7 == 0) {
				textCal.append("</tr>");
				if (sMonthWeek == chkWeek) {
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);

		}

		mav.addObject("txtCal", textCal.toString());

		mav.addObject("pensionInfo", pensionInfo);

		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));

		// 이미지 사이즈 구하기
		String popImg = (String) pensionInfo.get("event_img");
		if (null != popImg && !"".equals(popImg)) {
			String FilePath = req.getSession().getServletContext()
					.getRealPath(popImg);
			File eventImg = new File(FilePath);
			if (eventImg.isFile()) {
				Image img = new ImageIcon(FilePath).getImage();
				mav.addObject("eventW", img.getWidth(null));
				mav.addObject("eventH", img.getHeight(null));
			}
		}

		return mav;
	}

	/**
	 * 객실정보 불러오기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere101Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		if (null != vo.getSel_pr_no() && !"".equals(vo.getSel_pr_no())) {
			String[] ddd = vo.getSel_pr_no().split(",");
			List next = new ArrayList();
			for (int i = 0; i < ddd.length; i++) {
				next.add(ddd[i]);
			}
			vo.setNext_dates(next);
		}

		jsonMap.put("list", service.pere101Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 예약하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		Calendar d1 = Calendar.getInstance();
		Calendar d2 = Calendar.getInstance();// 오늘
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int dd = Integer.parseInt(vo.getReservation_dt().substring(6, 8));
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		d1.set(yyyy, mm, dd);// 지정일.
		if (d1.getTime().getTime() - d2.getTime().getTime() < 0) {
			// 오늘 이전은 조회할수 없습니다.

			mav.setViewName("redirect:./pere200Q.do?p_id=" + vo.getP_id()
					+ "&reservation_dt=" + frmDate.format(d2.getTime())
					+ "&sel_pr_no=" + vo.getSel_pr_no());
			return mav;
		}

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		// Map pensionInfo = service.pere203Q(vo);
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");

		// 설정한 기간 지나면 튕기도록 설정
		if (0 < reservation_use_month) {
			// d2
			// yyyy = Integer.parseInt(vo.getReservation_dt().substring(0,4));
			// mm = Integer.parseInt(vo.getReservation_dt().substring(4,6))-1;
			// dd = Integer.parseInt(vo.getReservation_dt().substring(6,8));

			d2.add(Calendar.MONTH, reservation_use_month);
			// d2.set(Calendar.DATE,d2.getActualMaximum(Calendar.DATE));
			if (d1.getTime().getTime() - d2.getTime().getTime() > 0) {
				// SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				mav.setViewName("redirect:./pere200Q.do?p_id=" + vo.getP_id()
						+ "&reservation_dt=" + frmDate.format(d2.getTime()));

				mav.setViewName("/common/close");
				// ModelAndView mav = new ModelAndView("/common/close");
				mav.addObject("redirect", "./pere200Q.do?p_id=" + vo.getP_id()
						+ "&reservation_dt=" + frmDate.format(d2.getTime()));
				mav.addObject("msg", reservation_use_month + "개월내에만 예약가능");
				return mav;
			}

		}

		// 부가서비스 가져오기
		mav.addObject("serviceList", service.pere200Q(vo));
		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}

	/**
	 * 예약정보 가져와서 달력에 표시하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200_1Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();// 오늘

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int dd = 1;

		d1.set(yyyy, mm, dd);// 지정일.
		d1.add(Calendar.MONTH, 1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0, 6) + "%");

		vo.setReservation_next_dt(frmDate.format(d1.getTime()) + "%");

		jsonMap.put("list", service.pere200_1Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 예약확인페이지 에서 객실별 예약현황 조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200_2Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();// 오늘

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int dd = 1;

		d1.set(yyyy, mm, dd);// 지정일.
		d1.add(Calendar.MONTH, 1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0, 6) + "%");

		vo.setReservation_next_dt(frmDate.format(d1.getTime()) + "%");

		jsonMap.put("list", service.pere200_2Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 예약확인페이지 에서 객실별 예약현황 조회 관리자용 정보 표시
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere200_3Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();// 오늘

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int dd = 1;

		d1.set(yyyy, mm, dd);// 지정일.
		d1.add(Calendar.MONTH, 1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0, 6) + "%");

		vo.setReservation_next_dt(frmDate.format(d1.getTime()) + "%");

		jsonMap.put("list", service.pere200_3Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 기간, 프로모션, 예약사항 정보 조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere201Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int dd = Integer.parseInt(vo.getReservation_dt().substring(6, 8));

		d1.set(yyyy, mm, dd);// 지정일.
		d1.add(Calendar.DATE, 8);
		vo.setReservation_next_dt(frmDate.format(d1.getTime()));
		if (null != vo.getSel_pr_no() && !"".equals(vo.getSel_pr_no())) {
			String[] ddd = vo.getSel_pr_no().split(",");
			List next = new ArrayList();
			for (int i = 0; i < ddd.length; i++) {
				next.add(ddd[i]);
			}
			vo.setNext_dates(next);
		}

		jsonMap.put("list", service.pere201Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 환불규정 동의
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere202Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
		int mm = Integer.parseInt(reservation_dt.substring(4, 6)) - 1;
		int dd = Integer.parseInt(reservation_dt.substring(6, 8));

		int totalPay = 0;

		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;

		List returnList = new ArrayList();

		vo.setP_id(p_id);

		// 펜션 요금 조회
		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {

			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];

			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);

			List nextDates = new ArrayList();

			// 연속된 방의 가격 다시 구하기
			for (int j = 0; j < rsv_days; j++) {
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();// 오늘

				d1.set(yyyy, mm, dd);// 지정일.
				d1.add(Calendar.DATE, j);
				//     //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");

				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);

				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList = service.pere202_2Q(vo);

			for (int j = 0; j < pList.size(); j++) {
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				// 해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);

				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);

				int totalMan = man_cnt + chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				// 인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan - use_man_cnt;
				if (pay_man < 0) {
					pay_man = 0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man * (add_usr_pay * 1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay += pay_man_m;
				totalPay += pay_man_m;
				// 인원수에 따른 가격 설정 끝

				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();// 오늘

				returnMap.put("nowdt", frmDate.format(d11.getTime()));

				if (null != pm_dt && !"".equals(pm_dt)) {
					// 설정된 값이 있을때
					int pm_pay = Integer.parseInt(String.valueOf(map
							.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt(String.valueOf(map
							.get("pm_per")));
					int pm_dc_m = Integer.parseInt(String.valueOf(map
							.get("pm_dc_m")));

					if (pm_per != 0 || pm_dc_m != 0) {
						int dc_pay = Integer.parseInt(String.valueOf(map
								.get("o_pm_pay")))
								- Integer.parseInt(String.valueOf(map
										.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay -= dc_pay;
						totalPayD1 -= dc_pay;
					} else {
						returnMap.put("dc_pay", 0);
					}

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				} else {
					// 설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0, 4));
					int mm1 = Integer.parseInt(aa.substring(4, 6)) - 1;
					int dd1 = Integer.parseInt(aa.substring(6, 8));
					System.out.println("aa : " + aa);
					Calendar d1 = Calendar.getInstance();// 오늘

					d1.set(yyyy1, mm1, dd1);// 지정일.
					//     //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
							java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());
					System.out.println("dayOfTheWeek : " + dayOfTheWeek);
					int pm_pay = 0;
					if ("일".equals(dayOfTheWeek) || "월".equals(dayOfTheWeek)
							|| "화".equals(dayOfTheWeek)
							|| "수".equals(dayOfTheWeek)
							|| "목".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_base") * 1000;
					} else if ("금".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_fri") * 1000;
					} else if ("토".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_sat") * 1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				}

				returnList.add(returnMap);
			}
		}

		// 객식 총 가격
		// totalPayD1 = totalPay;

		List rtAddSvcList = new ArrayList();
		// 부가서비스 가격 조회
		if (vo.getAs_no_idxs() != null && vo.getAs_no_idxs().length > 0) {
			List addServiceList = service.pere200Q(vo);
			for (int i = 0; i < vo.getAs_no_idxs().length; i++) {
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];

				for (int jj = 0; jj < addServiceList.size(); jj++) {
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if (mAs_no == as_no) {
						int as_pay = (Integer) map.get("as_pay");
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt * as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 += use_cnt * as_pay;
						break;
					}
				}
			}
		}
		totalPay += totalPayD2;

		mav.addObject("list", returnList);

		mav.addObject("totalPay", totalPay);
		mav.addObject("totalPayD1", totalPayD1);
		mav.addObject("totalPayD2", totalPayD2);
		mav.addObject("addPay", addPay);

		mav.addObject("paramMap", vo);
		// mav.addObject("p_id",p_id);

		// mav.addObject("list",returnList);
		// 환불규정
		mav.addObject("refundList", service.pere202_3Q(vo));

		// 부가서비스 리턴
		mav.addObject("rtAddSvcList", rtAddSvcList);

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		return mav;
	}

	/**
	 * 예약하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
		int mm = Integer.parseInt(reservation_dt.substring(4, 6)) - 1;
		int dd = Integer.parseInt(reservation_dt.substring(6, 8));

		// 기본 예약상태로 저장함
		vo.setRm_status("R");

		int totalPay = 0;

		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;

		List returnList = new ArrayList();

		vo.setP_id(p_id);

		// 펜션 요금 조회
		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {

			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];

			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);

			List nextDates = new ArrayList();

			// 연속된 방의 가격 다시 구하기
			for (int j = 0; j < rsv_days; j++) {
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();// 오늘

				d1.set(yyyy, mm, dd);// 지정일.
				d1.add(Calendar.DATE, j);
				//     //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");

				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);
				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList = service.pere202_2Q(vo);

			for (int j = 0; j < pList.size(); j++) {
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				// 해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);

				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);

				int totalMan = man_cnt + chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				// 인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan - use_man_cnt;
				if (pay_man < 0) {
					pay_man = 0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man * (add_usr_pay * 1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay += pay_man_m;
				totalPay += pay_man_m;
				// 인원수에 따른 가격 설정 끝

				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();// 오늘

				returnMap.put("nowdt", frmDate.format(d11.getTime()));

				if (null != pm_dt && !"".equals(pm_dt)) {
					// 설정된 값이 있을때
					int pm_pay = Integer.parseInt(String.valueOf(map
							.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt(String.valueOf(map
							.get("pm_per")));
					int pm_dc_m = Integer.parseInt(String.valueOf(map
							.get("pm_dc_m")));

					if (pm_per != 0 || pm_dc_m != 0) {
						int dc_pay = Integer.parseInt(String.valueOf(map
								.get("o_pm_pay")))
								- Integer.parseInt(String.valueOf(map
										.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay -= dc_pay;
						totalPayD1 -= dc_pay;
					} else {
						returnMap.put("dc_pay", 0);
					}

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				} else {
					// 설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0, 4));
					int mm1 = Integer.parseInt(aa.substring(4, 6)) - 1;
					int dd1 = Integer.parseInt(aa.substring(6, 8));

					Calendar d1 = Calendar.getInstance();// 오늘

					d1.set(yyyy1, mm1, dd1);// 지정일.
					//     //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
							java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay = 0;
					if ("일".equals(dayOfTheWeek) || "월".equals(dayOfTheWeek)
							|| "화".equals(dayOfTheWeek)
							|| "수".equals(dayOfTheWeek)
							|| "목".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_base") * 1000;
					} else if ("금".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_fri") * 1000;
					} else if ("토".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_sat") * 1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				}

				returnList.add(returnMap);
			}
		}

		// 객식 총 가격
		// totalPayD1 = totalPay;

		List rtAddSvcList = new ArrayList();
		// 부가서비스 가격 조회
		if (vo.getAs_no_idxs() != null && vo.getAs_no_idxs().length > 0) {
			List addServiceList = service.pere200Q(vo);
			for (int i = 0; i < vo.getAs_no_idxs().length; i++) {
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];

				for (int jj = 0; jj < addServiceList.size(); jj++) {
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if (mAs_no == as_no) {
						int as_pay = (Integer) map.get("as_pay");
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt * as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 += use_cnt * as_pay;
						break;
					}
				}

			}

		}
		totalPay += totalPayD2;

		mav.addObject("list", returnList);

		mav.addObject("totalPay", totalPay);
		mav.addObject("totalPayD1", totalPayD1);
		mav.addObject("totalPayD2", totalPayD2);
		mav.addObject("addPay", addPay);

		mav.addObject("paramMap", vo);

		// 환불규정
		// mav.addObject("refundList",service.pere202_3Q(vo));

		// 부가서비스 리턴
		mav.addObject("rtAddSvcList", rtAddSvcList);

		COMAVo codeVo = new COMAVo();
		// 전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List", comaService.coma104Q(codeVo));
		// 이메일
		codeVo.setCode_p_no("03");
		mav.addObject("code2List", comaService.coma104Q(codeVo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		List aList = petiService.peti300_1Q(petiVo);

		List aList1 = new ArrayList();
		List aList2 = new ArrayList();
		List aList3 = new ArrayList();
		List aList4 = new ArrayList();

		if (aList != null && 0 < aList.size()) {
			for (int i = 0; i < aList.size(); i++) {
				Map map = (Map) aList.get(i);
				if ("1".equals(map.get("paa_type"))) {
					// 계좌
					aList1.add(map);
				} else if ("2".equals(map.get("paa_type"))) {
					// 픽업장소
					aList2.add(map);
				} else if ("3".equals(map.get("paa_type"))) {
					// 픽업정보
					aList3.add(map);
				} else if ("4".equals(map.get("paa_type"))) {
					// 도착시간
					aList4.add(map);
				}
			}
		}
		mav.addObject("aList1", aList1);
		mav.addObject("aList2", aList2);
		mav.addObject("aList3", aList3);
		mav.addObject("aList4", aList4);

		return mav;
	}

	/**
	 * phone 체크
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203_1POP(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		// 세션 초기화
		req.getSession().setAttribute("smsChk", "");
		COMAVo codeVo = new COMAVo();
		// 전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List", comaService.coma104Q(codeVo));
		return mav;
	}

	/**
	 * sms 인증
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203_2Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		if ("Y".equals(pensionInfo.get("phone_yn"))) {
//sms 인증해야하는 부분
			
			Random rnd =new Random();
			StringBuffer buf =new StringBuffer();
			 
			for(int i=0;i<6;i++){
				buf.append((rnd.nextInt(10))); 
			}
				
			SMSUtil smsUtil = new SMSUtil();
			
			String send = pensionInfo.get("p_tel1")+"-"+pensionInfo.get("p_tel2")+"-"+pensionInfo.get("p_tel3");
			String recive = vo.getR_phone1()+"-"+vo.getR_phone2()+"-"+vo.getR_phone3();
			String msg = "["+pensionInfo.get("p_nm")+"]인증번호 "+buf.toString();
			
			String returnCode = smsUtil.send(send, recive, JspUtil.getByteSizeToString(msg.toString(),80));
			
			if("1".equals(returnCode)){
				//보내기 성공
				req.getSession().setAttribute("smsChk", buf.toString());
				jsonMap.put("returnType", "1");
								
			}else{
				//보내기 실패
				jsonMap.put("returnType", "3");
			}
			//sms 히스토리에 넣기
			vo.setP_nm((String) pensionInfo.get("p_nm") );
			vo.setFrom_no(send);
			vo.setTo_no(recive);
			vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),80));
			vo.setC_code(returnCode);
			vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));
			
			service.pere710Q(vo);
			if("1".equals(returnCode)){
				//sms 카운트 줄이기
				service.pere711Q(vo);
			}
		} else {
			// 바로 저장 완료
			jsonMap.put("returnType", "2");
		}
		mav.addObject("map", jsonMap);
		// r_phone2

		return mav;
	}

	/**
	 * 인증값과 같은지 비교
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere203_3Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		ModelAndView mav = new ModelAndView("common/toJson");

		String smsChk = (String) req.getSession().getAttribute("smsChk");

		Map jsonMap = new HashMap();
		if (vo.getSms_chk_data().equals(smsChk)) {
			// 인증번호 일치할때
			jsonMap.put("checkYN", "Y");
		} else {
			// 인증번호 불일치
			jsonMap.put("checkYN", "N");
		}
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 예약 확인
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere204Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();

		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
		int mm = Integer.parseInt(reservation_dt.substring(4, 6)) - 1;
		int dd = Integer.parseInt(reservation_dt.substring(6, 8));

		int totalPay = 0;

		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;

		List returnList = new ArrayList();

		vo.setP_id(p_id);

		// 펜션 요금 조회
		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {

			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];

			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);

			List nextDates = new ArrayList();

			// 연속된 방의 가격 다시 구하기
			for (int j = 0; j < rsv_days; j++) {
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();// 오늘

				d1.set(yyyy, mm, dd);// 지정일.
				d1.add(Calendar.DATE, j);
				//     //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");

				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);

				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList = service.pere202_2Q(vo);

			for (int j = 0; j < pList.size(); j++) {
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				// 해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);

				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);

				int totalMan = man_cnt + chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				// 인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan - use_man_cnt;
				if (pay_man < 0) {
					pay_man = 0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man * (add_usr_pay * 1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay += pay_man_m;
				totalPay += pay_man_m;
				// 인원수에 따른 가격 설정 끝

				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();// 오늘

				returnMap.put("nowdt", frmDate.format(d11.getTime()));

				if (null != pm_dt && !"".equals(pm_dt)) {
					// 설정된 값이 있을때
					int pm_pay = Integer.parseInt(String.valueOf(map
							.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt(String.valueOf(map
							.get("pm_per")));
					int pm_dc_m = Integer.parseInt(String.valueOf(map
							.get("pm_dc_m")));

					if (pm_per != 0 || pm_dc_m != 0) {
						int dc_pay = Integer.parseInt(String.valueOf(map
								.get("o_pm_pay")))
								- Integer.parseInt(String.valueOf(map
										.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay -= dc_pay;
						totalPayD1 -= dc_pay;
					} else {
						returnMap.put("dc_pay", 0);
					}

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				} else {
					// 설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0, 4));
					int mm1 = Integer.parseInt(aa.substring(4, 6)) - 1;
					int dd1 = Integer.parseInt(aa.substring(6, 8));

					Calendar d1 = Calendar.getInstance();// 오늘

					d1.set(yyyy1, mm1, dd1);// 지정일.
					//     //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
							java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay = 0;
					if ("일".equals(dayOfTheWeek) || "월".equals(dayOfTheWeek)
							|| "화".equals(dayOfTheWeek)
							|| "수".equals(dayOfTheWeek)
							|| "목".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_base") * 1000;
					} else if ("금".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_fri") * 1000;
					} else if ("토".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_sat") * 1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				}

				returnList.add(returnMap);
			}
		}

		// 객식 총 가격
		// totalPayD1 = totalPay;

		List rtAddSvcList = new ArrayList();
		// 부가서비스 가격 조회
		if (vo.getAs_no_idxs() != null && vo.getAs_no_idxs().length > 0) {
			List addServiceList = service.pere200Q(vo);
			for (int i = 0; i < vo.getAs_no_idxs().length; i++) {
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];

				for (int jj = 0; jj < addServiceList.size(); jj++) {
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if (mAs_no == as_no) {
						int as_pay = (Integer) map.get("as_pay");
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt * as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 += use_cnt * as_pay;
						break;
					}
				}

			}

		}
		totalPay += totalPayD2;

		mav.addObject("list", returnList);

		mav.addObject("totalPay", totalPay);
		mav.addObject("totalPayD1", totalPayD1);
		mav.addObject("totalPayD2", totalPayD2);
		mav.addObject("addPay", addPay);

		// 부가서비스 리턴
		mav.addObject("rtAddSvcList", rtAddSvcList);

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		Calendar chkDt = Calendar.getInstance();// 오늘

		int tm = (Integer) pensionInfo.get("wait_time");
		chkDt.add(Calendar.HOUR, tm);

		SimpleDateFormat frmChkDt = new SimpleDateFormat("yyyyMMddHHmmss");

		vo.setRm_wait_time(frmChkDt.format(chkDt.getTime()));

		mav.addObject("paramMap", vo);
		return mav;
	}

	/**
	 * 예약 저장하기(사용자)
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere204T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("/common/close");
		String smsChk = (String) req.getSession().getAttribute("smsChk");
		if (vo.getSms_chk_data() != null
				&& !vo.getSms_chk_data().equals(smsChk)) {
			mav.addObject("historyBackYn", "Y");
			mav.addObject("msg", "SMS 인증번호가 없습니다");
			return mav;
		}
		// 기본 예약상태로 저장함
		vo.setRm_status("R");

		// sms 방명, 숙박일, 등록일
		String smsRoom_nm = "";
		String smsReservation_dt = "";
		String smsReg_dt = "";

		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
		int mm = Integer.parseInt(reservation_dt.substring(4, 6)) - 1;
		int dd = Integer.parseInt(reservation_dt.substring(6, 8));

		int totalPay = 0;

		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;

		List returnList = new ArrayList();

		vo.setP_id(p_id);

		// 시작일시 저장 sms
		String startDate = "";
		String startRooms = "";
		// sms 보낼때 몇박인지
		int bak = 0;
		// 펜션 요금 조회
		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {

			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];

			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);

			List nextDates = new ArrayList();

			// 연속된 방의 가격 다시 구하기
			for (int j = 0; j < rsv_days; j++) {
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();// 오늘

				d1.set(yyyy, mm, dd);// 지정일.
				d1.add(Calendar.DATE, j);
				//     //요일 출력.
				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList = service.pere202_2Q(vo);

			for (int j = 0; j < pList.size(); j++) {
				bak++;
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");
				// 해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				if (i == 0) {
					int yyyy1 = Integer.parseInt(aa.substring(0, 4));
					int mm1 = Integer.parseInt(aa.substring(4, 6)) - 1;
					int dd1 = Integer.parseInt(aa.substring(6, 8));

					startDate = aa.substring(0, 4) + "-" + aa.substring(4, 6)
							+ "-" + aa.substring(6, 8);
					startRooms = (String) payInfo.get("room_nm");
				}

				returnMap.put("pr_no", pr_no);
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				returnMap.put("add_usr_pay", add_usr_pay);

				int totalMan = man_cnt + chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				// 인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");
				int pay_man = totalMan - use_man_cnt;
				if (pay_man < 0) {
					pay_man = 0;
				}
				returnMap.put("pay_man", pay_man);
				int pay_man_m = pay_man * (add_usr_pay * 1000);
				returnMap.put("pay_man_m", pay_man_m);
				addPay += pay_man_m;
				totalPay += pay_man_m;
				// 인원수에 따른 가격 설정 끝

				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();// 오늘

				// sms 관련 정보
				if (i == 0 && j == 0) {
					SimpleDateFormat weekday222 = new SimpleDateFormat(
							"yyyy-MM-dd");
					smsRoom_nm = startRooms;
					smsReservation_dt = startDate;
					smsReg_dt = weekday222.format(d11.getTime());
					// if(vo.getPr_no_cnts().length>1){
					// smsRoom_nm = startRooms+".";
					// smsReservation_dt = startDate+".";
					// }else if(rsv_days>1){
					// smsReservation_dt = startDate+".";
					// }
				}
				returnMap.put("nowdt", frmDate.format(d11.getTime()));

				if (null != pm_dt && !"".equals(pm_dt)) {
					// 설정된 값이 있을때
					int pm_pay = Integer.parseInt(String.valueOf(map
							.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt(String.valueOf(map
							.get("pm_per")));
					int pm_dc_m = Integer.parseInt(String.valueOf(map
							.get("pm_dc_m")));

					if (pm_per != 0 || pm_dc_m != 0) {
						int dc_pay = Integer.parseInt(String.valueOf(map
								.get("o_pm_pay")))
								- Integer.parseInt(String.valueOf(map
										.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay -= dc_pay;
						totalPayD1 -= dc_pay;
					} else {
						returnMap.put("dc_pay", 0);
					}

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				} else {
					// 설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0, 4));
					int mm1 = Integer.parseInt(aa.substring(4, 6)) - 1;
					int dd1 = Integer.parseInt(aa.substring(6, 8));

					Calendar d1 = Calendar.getInstance();// 오늘

					d1.set(yyyy1, mm1, dd1);// 지정일.
					//     //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
							java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay = 0;
					if ("일".equals(dayOfTheWeek) || "월".equals(dayOfTheWeek)
							|| "화".equals(dayOfTheWeek)
							|| "수".equals(dayOfTheWeek)
							|| "목".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_base") * 1000;
					} else if ("금".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_fri") * 1000;
					} else if ("토".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_sat") * 1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				}

				returnList.add(returnMap);
			}
		}

		// 객식 총 가격
		// totalPayD1 = totalPay;

		List rtAddSvcList = new ArrayList();
		// 부가서비스 가격 조회
		if (vo.getAs_no_idxs() != null && vo.getAs_no_idxs().length > 0) {
			List addServiceList = service.pere200Q(vo);
			for (int i = 0; i < vo.getAs_no_idxs().length; i++) {
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];

				for (int jj = 0; jj < addServiceList.size(); jj++) {
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if (mAs_no == as_no) {
						int as_pay = (Integer) map.get("as_pay");

						map.put("as_no", mAs_no);
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt * as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 += use_cnt * as_pay;
						break;
					}
				}

			}

		}
		totalPay += totalPayD2;

		Map data = new HashMap();
		data.put("paramMap", vo);
		data.put("list", returnList);
		// 부가서비스 리턴
		data.put("rtAddSvcList", rtAddSvcList);
		//
		// mav.addObject("totalPay",totalPay);
		// mav.addObject("totalPayD1",totalPayD1);
		// mav.addObject("totalPayD2",totalPayD2);
		// mav.addObject("addPay",addPay);

		// 예약한 객실수
		data.put("smsRoomCnt", vo.getPr_no_cnts().length);
		// 총 가격
		data.put("totalPay", totalPay);
		// 객실명
		data.put("smsRoom_nm", smsRoom_nm);
		// 예약일
		data.put("smsReservation_dt", smsReservation_dt);
		// 등록일
		data.put("smsReg_dt", smsReg_dt);
		// 숙박일
		data.put("smsBak", bak);

		service.pere204T(data);

		mav.setViewName("/common/close");
		mav.addObject("redirect", "./pere200Q.do?p_id=" + vo.getP_id()
				+ "&reservation_dt=" + reservation_dt);
		mav.addObject("msg", "예약되었습니다");
		return mav;
	}

	/**
	 * 예약안내
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere300Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		Map jsonMap = new HashMap();
		mav.addObject("refundList", service.pere202_3Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy");
		Calendar d1 = Calendar.getInstance();
		int yyyy = Integer.parseInt(frmDtAll.format(d1.getTime()));
		int age = yyyy - 19;
		mav.addObject("yyyy", yyyy);
		mav.addObject("age", age);

		// mav.addObject("pensionInfo",service.pere203Q(vo));
		return mav;
	}

	/**
	 * 요금설정
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere400Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		Map jsonMap = new HashMap();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");
		Calendar d1 = Calendar.getInstance();
		mav.addObject("nDtAll", frmDtAll.format(d1.getTime()));

		mav.addObject("pensionInfo", pensionInfo);

		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}

	/**
	 * 요금 저장 프로세스
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere400T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere400Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "저장되었습니다");

		service.pere400T(vo);
		return mav;
	}

	/**
	 * 프로모션 정보 가져오기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere400_1Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		Calendar d1 = Calendar.getInstance();// 오늘

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int dd = 1;

		d1.set(yyyy, mm, dd);// 지정일.
		d1.add(Calendar.MONTH, 1);
		vo.setReservation_dt(vo.getReservation_dt().substring(0, 6) + "%");
		vo.setReservation_next_dt(frmDate.format(d1.getTime()) + "%");

		jsonMap.put("list", service.pere400_1Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 펜션 예약 조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere500Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));

		COMAVo codeVo = new COMAVo();
		// 전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List", comaService.coma104Q(codeVo));
		return mav;
	}

	/**
	 * 예약내용 불러오기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere501Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();

		List reservationList = service.pere501Q(vo);

		mav.addObject("reservationList", reservationList);

		if (null != reservationList && 0 < reservationList.size()) {
			// 자료가 있을때
			Map data = (Map) reservationList.get(0);
			mav.addObject("paramMap", data);

			if (vo.getRm_no() == 0) {
				vo.setRm_no((Integer) data.get("rm_no"));
			}
			List list = service.pere501_2Q(vo);
			List returnList = new ArrayList();

			Calendar nowDate = Calendar.getInstance();// 오늘
			nowDate.set(Calendar.HOUR_OF_DAY, 1);
			nowDate.set(Calendar.MINUTE, 1);
			nowDate.set(Calendar.SECOND, 1);

			boolean cancelBtn = true;
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				Calendar reservationDt = Calendar.getInstance();// 오늘
				String reservation_dt = (String) map.get("reservation_dt");
				int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
				int mm = Integer.parseInt(reservation_dt.substring(4, 6));
				int dd = Integer.parseInt(reservation_dt.substring(6, 8));
				reservationDt.set(yyyy, mm - 1, dd, 1, 1, 1);

				if ((nowDate.getTime().getTime() - reservationDt.getTime()
						.getTime()) > 0) {
					map.put("cancelYN", "N");
				} else {
					cancelBtn = false;
					map.put("cancelYN", "Y");
				}
				returnList.add(map);
			}
			// 예약 객실목록
			mav.addObject("list", returnList);

			// 예약 객실목록
			// mav.addObject("list", service.pere501_2Q(vo));

			// 취소 객실 목록
			mav.addObject("cancelList", service.pere501_4Q(vo));

			// 부가서비스 목록
			mav.addObject("rtAddSvcList", service.pere501_3Q(vo));
			mav.addObject("cancelBtn", cancelBtn);
		} else {
			// 자료가 없을때
			mav.setViewName("/common/close");
			mav.addObject("redirect", "./pere500Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "등록된 예약 자료가 없습니다.");
			return mav;
		}
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		return mav;
	}

	/**
	 * 펜션 예약취소(사용자)
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere502Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();

		

		boolean chkRelay = false;
		//연박 취소설정 체크 연박일 경우 하루만 취소 불가능하다
		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				List chkList = service.pere502_5Q(vo);

				if(chkList.size()>0){
					for (int ij = 0; ij < chkList.size() ; ij++) {
						Map relMap = (Map) chkList.get(ij);
						String chk_pm_dt = relMap.get("pm_dt").toString();
						String chk_p_id = relMap.get("p_id").toString();
						int chk_pr_no = Integer.parseInt(relMap.get("pr_no").toString());
						
						boolean chkRelYn = false;
						
						for (int ik = 0; ik < vo.getIdxs().length; ik++) {
							if(chk_pr_no == vo.getPr_nos()[vo.getIdxs()[ik]]
									&& chk_p_id.equals(vo.getP_id())
									&& chk_pm_dt.equals(vo.getReservation_dts()[vo.getIdxs()[ik]])
									){
								chkRelYn=true;
							}
							if(chkRelYn){
								break;
							}
						}
						if(!chkRelYn){
							chkRelay = true;
						}
						
					}	
				}
				if(chkRelay){
					break;
				}
			}
		}
		
		//chkRelay가 true면 연박삭제해야한다
		if(chkRelay){
			mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "연박설정이 있습니다 연박으로 예약한 자료는 모두 삭제하셔야 합니다");
			mav.addObject("historyBackYn", "Y");

			return mav;

		}
		
		List pList = new ArrayList();
		List sList = new ArrayList();

		boolean chkComplet = false;
		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				Map pMap = service.pere502_1Q(vo);
				pList.add(pMap);
				if ("C".equals(pMap.get("rm_status"))) {
					// 등록된 자료
					chkComplet = true;
				}

			}
		}
		if (vo.getIdxs2() != null && 0 < vo.getIdxs2().length) {
			for (int i = 0; i < vo.getIdxs2().length; i++) {
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);

				Map sMap = service.pere502_3Q(vo);
				sList.add(sMap);
				if ("C".equals(sMap.get("as_status"))) {
					// 등록된 자료
					chkComplet = true;
				}
			}
		}
		
		if (chkComplet) {
			// 환불 자료로 넘어간다
			mav = new ModelAndView("usr/pe/re/pere502Q");
			// mav.setViewName("/usr/pr/re/pere502Q");
			Map refund = service.pere202_3Q(vo);
			mav.addObject("refundList", refund);
			mav.addObject("paramMap", vo);
			// 취소할 예약 객실목록

			if (pList != null && 0 < pList.size()) {
				vo.setNext_dates(pList);
				List list = service.pere501_5Q(vo);
				List returnList = new ArrayList();
				if (list != null && 0 < list.size()) {
					for (int i = 0; i < list.size(); i++) {
						Map data = (Map) list.get(i);

						int dateCha = Integer.parseInt(String.valueOf(data
								.get("dateCha")));
						if (dateCha < 0) {
							dateCha = 0;
						}
						if (dateCha > 7) {
							int per = (Integer) refund.get("general");
							data.put("per", per);
							data.put("r_pay", (Integer) data.get("total_pay")
									- (Integer) data.get("add_pay"));
							int r_pay = Integer.parseInt(Long
									.toString((long) (((Integer) data
											.get("total_pay") - (Integer) data
											.get("add_pay")) * (per / 100.0))));

							r_pay = r_pay / 1000;
							r_pay = r_pay * 1000;
							data.put("r_pay", r_pay);
						} else {
							int per = (Integer) refund.get("day_a_" + dateCha);
							data.put("per", per);
							int r_pay = Integer.parseInt(Long
									.toString((long) (((Integer) data
											.get("total_pay") - (Integer) data
											.get("add_pay")) * (per / 100.0))));
							// 절삭 처리
							r_pay = r_pay / 1000;
							r_pay = r_pay * 1000;
							data.put("r_pay", r_pay);
						}

						returnList.add(data);
					}
				}
				// refund

				mav.addObject("list", returnList);
			}

			// 부가서비스 목록
			if (sList != null && 0 < sList.size()) {
				vo.setNext_dates(sList);
				mav.addObject("rtAddSvcList", service.pere501_6Q(vo));
			}

			COMAVo codeVo = new COMAVo();
			// 입금반환 은행
			codeVo.setCode_p_no("04");
			mav.addObject("codeList04", comaService.coma104Q(codeVo));

			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);

			mav.addObject("pensionInfo", pensionInfo);
			return mav;
		} else {

			
			// 자료를 옮기고 취소처리한다.
			if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
				for (int i = 0; i < vo.getIdxs().length; i++) {
					vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
					vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
					service.pere600_1T(vo);
					service.pere600_2T(vo);
				}
			}

			if (vo.getIdxs2() != null && 0 < vo.getIdxs2().length) {
				for (int i = 0; i < vo.getIdxs2().length; i++) {
					vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
					service.pere502_3T(vo);
				}
			}
			
			//연박살리기
			if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
				List relList = new ArrayList();
				for (int i = 0; i < vo.getIdxs().length; i++) {
					Map dt = new HashMap();
					
					dt.put("pr_no", vo.getPr_nos()[vo.getIdxs()[i]]);
					dt.put("reservation_dt", vo.getReservation_dts()[vo.getIdxs()[i]]);
					dt.put("p_id", vo.getP_id());
					
					List rdList =service.pere502_9Q(dt);
					for(int j=0; j < rdList.size();j++){
						Map rdMap = (Map) rdList.get(j);
						String rd = (String) rdMap.get("reservation_dt");
						if(rd != null &&  !"".equals(rd)){
							dt.put("reservation_dt", rd);
							service.pere502_10T(dt);
							
							service.pere502_7T(dt);	
						}	
					}
					
				}
			}

			Map sms_data = service.pere502_4Q(vo);

			// sms 보내기 시작
			// sms 보내기
			String data = (String) sms_data.get("r_info");

			String into = data.split("@")[1];
			int dayCnt = 0;
			String reservation_dt = "";
			String room_nm = "";

			for (int j = 0; j < into.split(";").length; j++) {
				String[] vals = into.split(";")[j].split(":");
				// 입금대기자 정보(부가서비스
				// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

				String[] val4 = vals[4].split(",");
				for (int k = 0; k < val4.length; k++) {
					dayCnt++;

					if (k == 0 && j == 0) {
						reservation_dt = val4[k].substring(0, 4) + "."
								+ val4[k].substring(4, 6) + "."
								+ val4[k].substring(6, 8);
						room_nm = vals[0];
					}
				}
			}

			Map smsMap = service.pere1100Q(vo);
			SMSUtil smsUtil = new SMSUtil();
			
			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);
			if("Y".equals(pensionInfo.get("sms_send_yn"))){
				int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
				
				if(chk_sms_cnt > 0){

					if ("Y".equals(smsMap.get("f1"))) {
						// 사용자에게 보내기
						// [펜션명]2009-00-00/객실명 예약취소완료
						StringBuffer msg = new StringBuffer();
						String send = sms_data.get("p_phone1") + "-"
								+ sms_data.get("p_phone2") + "-"
								+ sms_data.get("p_phone3");
						String recive = (String) sms_data.get("r_phone1") + "-"
								+ (String) sms_data.get("r_phone2") + "-"
								+ (String) sms_data.get("r_phone3");
						msg.append("[");
						msg.append(sms_data.get("p_nm"));
						msg.append("] ");
						msg.append(reservation_dt);
						if (dayCnt > 1) {
							msg.append("외 ");
							msg.append((dayCnt - 1));
							msg.append("일");
						}
						msg.append("/");
						msg.append(room_nm);
						if (into.split(";").length > 1) {
							msg.append("외 ");
							msg.append((into.split(";").length - 1));
							msg.append("객실");
						}
						msg.append(" 예약취소 완료");

						String returnCode = smsUtil.send(send, recive,
								JspUtil.getByteSizeToString(msg.toString(), 80));
						// sms 히스토리에 넣기
						vo.setP_nm((String) sms_data.get("p_nm"));
						vo.setFrom_no(send);
						vo.setTo_no(recive);
						vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),
								80));
						vo.setC_code(returnCode);
						vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

						service.pere710Q(vo);
						if ("1".equals(returnCode)) {
							// sms 카운트 줄이기
							service.pere711Q(vo);
						}
					}
					if ("Y".equals(smsMap.get("f2"))) {
						// 관리자에게 보내기
						// [취소완료]2009-00-00/객실명/1박/아무개
						StringBuffer msg = new StringBuffer();
						String send = (String) sms_data.get("r_phone1") + "-"
								+ (String) sms_data.get("r_phone2") + "-"
								+ (String) sms_data.get("r_phone3");
						String recive = sms_data.get("p_phone1") + "-"
								+ sms_data.get("p_phone2") + "-"
								+ sms_data.get("p_phone3");

						msg.append("[취소완료]");
						msg.append(reservation_dt);
						if (dayCnt > 1) {
							msg.append("외 ");
							msg.append((dayCnt - 1));
							msg.append("일");
						}
						msg.append("/");
						msg.append(room_nm);
						if (into.split(";").length > 1) {
							msg.append("외 ");
							msg.append((into.split(";").length - 1));
							msg.append("객실");
						}
						msg.append("/");
						msg.append(dayCnt);
						msg.append("/");
						msg.append(sms_data.get("reservation_nm"));

						String returnCode = smsUtil.send(send, recive,
								JspUtil.getByteSizeToString(msg.toString(), 80));
						// sms 히스토리에 넣기
						vo.setP_nm((String) sms_data.get("p_nm"));
						vo.setFrom_no(send);
						vo.setTo_no(recive);
						vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(),
								80));
						vo.setC_code(returnCode);
						vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

						service.pere710Q(vo);
						if ("1".equals(returnCode)) {
							// sms 카운트 줄이기
							service.pere711Q(vo);
						}
					}
					// sms 보내기 종료					
				}
			}

			// 저장후 다른곳으로 포워딩
			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "예약취소 되었습니다.");

		}

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		return mav;
	}

	/**
	 * 환불객실 취소 프로세스(사용자)
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere503T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("/common/close");

		mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "예약취소 환불요청 되었습니다.");

		List pList = new ArrayList();
		List sList = new ArrayList();

		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				Map pMap = service.pere502_1Q(vo);
				pList.add(pMap);
			}
		}
		if (vo.getIdxs2() != null && 0 < vo.getIdxs2().length) {
			for (int i = 0; i < vo.getIdxs2().length; i++) {
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);

				Map sMap = service.pere502_3Q(vo);
				sList.add(sMap);

			}
		}

		// 수수료
		int total_penalty_pay = 0;
		// 총 금액
		int total_pay = 0;

		Map refund = service.pere202_3Q(vo);
		// 취소할 예약 객실목록

		if (pList != null && 0 < pList.size()) {
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if (list != null && 0 < list.size()) {
				for (int i = 0; i < list.size(); i++) {
					Map data = (Map) list.get(i);
					vo.setReg_dt((String) data.get("reg_dt"));
					vo.setReservation_dt((String) data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf(data
							.get("pr_no"))));
					total_pay += Integer.parseInt(String.valueOf(data
							.get("total_pay")));
					int dateCha = Integer.parseInt(String.valueOf(data
							.get("dateCha")));
					if (dateCha < 0) {
						dateCha = 0;
					}
					if (dateCha > 7) {
						int per = (Integer) refund.get("general");
						int add_pay = (Integer) data.get("add_pay");
						data.put("per", per);
						int r_pay = Integer.parseInt(Long
								.toString((long) (((Integer) data
										.get("total_pay") - (Integer) data
										.get("add_pay")) * (per / 100.0))));

						// 절삭 처리
						r_pay = r_pay / 1000;
						r_pay = r_pay * 1000;
						int penalty_pay = (Integer) data.get("total_pay")
								- r_pay - add_pay;
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay += r_pay + add_pay;
						vo.setPenalty_pay(penalty_pay);
					} else {
						int per = (Integer) refund.get("day_a_" + dateCha);
						int add_pay = (Integer) data.get("add_pay");
						data.put("per", per);
						int r_pay = Integer.parseInt(Long
								.toString((long) (((Integer) data
										.get("total_pay") - (Integer) data
										.get("add_pay")) * (per / 100.0))));
						// 절삭 처리
						r_pay = r_pay / 1000;
						r_pay = r_pay * 1000;
						int penalty_pay = (Integer) data.get("total_pay")
								- r_pay - add_pay;
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay += r_pay + add_pay;
						vo.setPenalty_pay(penalty_pay);
					}
				}
			}
		}

		// 부가서비스 목록
		if (sList != null && 0 < sList.size()) {
			for (int i = 0; i < sList.size(); i++) {
				Map data = (Map) sList.get(i);
				total_penalty_pay += (Integer) data.get("total_pay");
				total_pay += Integer.parseInt(String.valueOf(data
						.get("total_pay")));
			}
		}
//		System.out.println(1212);
		// 총 금액
		vo.setTotal_pay(total_pay);
		// 수수료
		vo.setPenalty_pay(total_penalty_pay);
		// 최종 환불요청 자료에 넣기
		vo.setRe_no(service.pere503_4T(vo));
		List smsRms = new ArrayList();
		if (pList != null && 0 < pList.size()) {
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if (list != null && 0 < list.size()) {
				for (int i = 0; i < list.size(); i++) {
					Map data = (Map) list.get(i);
					smsRms.add(data.get("rm_no"));
					vo.setReservation_dt((String) data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf(data
							.get("pr_no"))));
					int dateCha = Integer.parseInt(String.valueOf(data
							.get("dateCha")));
					if (dateCha < 0) {
						dateCha = 0;
					}

					int per = 100;
					if (dateCha > 7) {
						per = (Integer) refund.get("general");
					} else {
						per = (Integer) refund.get("day_a_" + dateCha);
					}
					int add_pay = (Integer) data.get("add_pay");
					// data.put("per", per);
					int r_pay = Integer
							.parseInt(Long.toString((long) (((Integer) data
									.get("total_pay") - (Integer) data
									.get("add_pay")) * (per / 100.0))));
					// 절삭 처리
					r_pay = r_pay / 1000;
					r_pay = r_pay * 1000;
					int penalty_pay = r_pay + add_pay;
					// data.put("penalty_pay", penalty_pay);
					// total_penalty_pay+= r_pay+add_pay;
					vo.setPenalty_per(per);
					vo.setPenalty_pay(penalty_pay);

					// 데이터 환불요청 후 취소자료에 넣기
					service.pere503_1T(vo);

				}
			}

			// 예약객실 취소처리
			vo.setNext_dates(smsRms);

			// 삭제전 sms 보내기

			
			
			// sms 보내기
			Map sms_data = service.pere502_4Q(vo);
			vo.setNext_dates(pList);

			Map smsMap = service.pere1100Q(vo);
			SMSUtil smsUtil = new SMSUtil();

			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);

			if("Y".equals(pensionInfo.get("sms_send_yn"))){
				int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
				
				if(chk_sms_cnt > 0){
					if (null != sms_data) {
						// 메세지 만들기
						String data = (String) sms_data.get("r_info");

						String into = data.split("@")[1];
						int dayCnt = 0;
						String reservation_dt = "";
						String room_nm = "";

						for (int j = 0; j < into.split(";").length; j++) {
							String[] vals = into.split(";")[j].split(":");
							// 입금대기자 정보(부가서비스
							// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

							String[] val4 = vals[4].split(",");
							for (int k = 0; k < val4.length; k++) {
								dayCnt++;
								if (k == 0 && j == 0) {
									reservation_dt = val4[k].substring(0, 4) + "."
											+ val4[k].substring(4, 6) + "."
											+ val4[k].substring(6, 8);
									room_nm = vals[0];
									// if(into.split(";").length>1){
									// reservation_dt+=".";
									// room_nm+=".";
									// }
								}
							}
						}
						// 메세지 만들기 종료

						// [펜션명]아무개님 예약취소 완료:50.000원 익일6시이내
						// 입금됩니다
						DecimalFormat decFormat = new java.text.DecimalFormat(
								"###,###,###,###");

						// StringBuffer msg = new StringBuffer();
						// msg.append("[");
						// msg.append(pensionInfo.get("p_nm"));
						// msg.append("] ");
						// msg.append(sms_data.get("reservation_nm"));
						// msg.append("님 예약취소 완료 : ");
						// msg.append(decFormat.format(total_penalty_pay) );
						// msg.append("원 익일 6시이내 입금됩니다.");

						// if("Y".equals(smsMap.get("g1"))){
						if ("Y".equals(smsMap.get("f1"))) {
							// 사용자에게 보내기
							// 예약자 [펜션명]2009-00-00/객실명 예약취소요청
							//
							StringBuffer msg = new StringBuffer();
							msg.append("[");
							msg.append(pensionInfo.get("p_nm"));
							msg.append("] ");
							msg.append(reservation_dt);
							if (dayCnt > 1) {
								msg.append("외 ");
								msg.append((dayCnt - 1));
								msg.append("일");
							}
							msg.append("/");
							msg.append(room_nm);
							if (into.split(";").length > 1) {
								msg.append("외 ");
								msg.append((into.split(";").length - 1));
								msg.append("객실");
							}
							msg.append(" 예약취소요청");

							// msg.append(decFormat.format(total_penalty_pay) );
							// msg.append("원 익일 6시이내 입금됩니다.");

							String send = pensionInfo.get("p_phone1") + "-"
									+ pensionInfo.get("p_phone2") + "-"
									+ pensionInfo.get("p_phone3");
							String recive = (String) sms_data.get("r_phone1") + "-"
									+ sms_data.get("r_phone2") + "-"
									+ sms_data.get("r_phone3");

							String returnCd = smsUtil.send(send, recive,
									JspUtil.getByteSizeToString(msg.toString(), 80));
							// sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm"));
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(
									msg.toString(), 80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

							service.pere710Q(vo);
							if ("1".equals(returnCd)) {
								service.pere711Q(vo);
							}
							// sms 히스토리에 넣기 종료
						}
						// if("Y".equals(smsMap.get("g2"))){
						if ("Y".equals(smsMap.get("f2"))) {
							// 관리자에게 보내기
							// 관리자 [취소요청]2009-00-00/객실명/1박/아무개
							StringBuffer msg = new StringBuffer();
							msg.append("[취소요청] ");

							msg.append(reservation_dt);
							if (dayCnt > 1) {
								msg.append("외 ");
								msg.append((dayCnt - 1));
								msg.append("일");
							}
							msg.append("/");
							msg.append(room_nm);
							if (into.split(";").length > 1) {
								msg.append("외 ");
								msg.append((into.split(";").length - 1));
								msg.append("객실");
							}
							msg.append("/");
							msg.append(dayCnt);
							msg.append("박");
							msg.append("/");
							msg.append(sms_data.get("reservation_nm"));

							String send = (String) sms_data.get("r_phone1") + "-"
									+ sms_data.get("r_phone2") + "-"
									+ sms_data.get("r_phone3");
							String recive = pensionInfo.get("p_phone1") + "-"
									+ pensionInfo.get("p_phone2") + "-"
									+ pensionInfo.get("p_phone3");

							String returnCd = smsUtil.send(send, recive,
									JspUtil.getByteSizeToString(msg.toString(), 80));
							// sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm"));
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(
									msg.toString(), 80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

							service.pere710Q(vo);
							if ("1".equals(returnCd)) {
								service.pere711Q(vo);
							}
						}

					}
					// sms 보내기 끝
				}
			}
			

			// 예약객실 삭제
			service.pere503_2T(vo);
			

			//연박살리기
			if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
				List relList = new ArrayList();
				for (int i = 0; i < vo.getIdxs().length; i++) {
					Map dt = new HashMap();
					
					dt.put("pr_no", vo.getPr_nos()[vo.getIdxs()[i]]);
					dt.put("reservation_dt", vo.getReservation_dts()[vo.getIdxs()[i]]);
					dt.put("p_id", vo.getP_id());
					
					List rdList =service.pere502_9Q(dt);
					for(int j=0; j < rdList.size();j++){
						Map rdMap = (Map) rdList.get(j);
						String rd = (String) rdMap.get("reservation_dt");
						if(rd != null &&  !"".equals(rd)){
							dt.put("reservation_dt", rd);
							service.pere502_10T(dt);
							
							service.pere502_7T(dt);	
						}	
					}
					
				}
			}
		}

		// 부가서비스 목록
		if (sList != null && 0 < sList.size()) {
			vo.setNext_dates(sList);
			service.pere503_3T(vo);
		}

		return mav;
	}

	/**
	 * 예약종합정보
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere700Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl", "pere700Q.do");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		String selDt = "";
		String selDtTmp = "";

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime()) + "%");
		} else {
			selDt = vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt() + "%");
		}
		mav.addObject("selDtTmp", selDtTmp);
		if (selDt.length() == 6) {
			mav.addObject("selDt", selDt + "01");
		} else if (selDt.length() == 8) {
			mav.addObject("selDt", selDt);
		}

		if (null == vo.getRm_status() || "".equals(vo.getRm_status())) {
			vo.setRm_status("R");
		}

		if (null != vo.getSrc_val() && !"".equals(vo.getSrc_val())) {
			vo.setSrc_val("%" + vo.getSrc_val() + "%");
		}

		List list = service.pere700Q(vo);
		List rList = new ArrayList();
		if (list != null && 0 < list.size()) {
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				String data = (String) map.get("r_info");

				// 부가서비스 가격
				String add_svc = data.split("@")[0];

				String into = data.split("@")[1];
				int pay = 0;
				String room_nm = "";
				String reg_dt = "";
				String use_man_cnt = "";
				String use_cnt = "";
				String reservation_dt = "";
				String reservation_dt_tmp = "";
				String day_cnt = "";
				String total_pay = "";

				for (int j = 0; j < into.split(";").length; j++) {

					String[] vals = into.split(";")[j].split(":");
					// 입금대기자 정보(부가서비스
					// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if (j != 0) {
						room_nm += "</br>";
						reg_dt += "</br>";
						use_man_cnt += "</br>";
						use_cnt += "</br>";
						reservation_dt += "</br>";
						reservation_dt_tmp += "</br>";
						day_cnt += "</br>";
						total_pay += "</br>";
					}
					room_nm += vals[0];

					use_man_cnt += vals[2] + "/" + vals[3];

					String[] val4 = vals[4].split(",");
					for (int k = 0; k < val4.length; k++) {
						if (k == 0) {
							reservation_dt += val4[k].substring(4, 6) + "."
									+ val4[k].substring(6, 8);
						} else {
							if (val4[k - 1].substring(4, 6).equals(
									val4[k].substring(4, 6))) {
								reservation_dt += ", "
										+ val4[k].substring(6, 8);
							} else {
								reservation_dt += ", "
										+ val4[k - 1].substring(4, 6) + "."
										+ val4[k].substring(6, 8);
							}

						}
					}
					reservation_dt += "(" + vals[1].substring(2, 4) + "."
							+ vals[1].substring(4, 6) + "."
							+ vals[1].substring(6, 8) + ")";

					day_cnt += vals[5] + "박";
					total_pay += vals[6];

					pay += Integer.parseInt(vals[6]);
				}

				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				map.put("reservation_dt", reservation_dt);
				map.put("day_cnt", day_cnt);

				map.put("total_pay", (pay + Integer.parseInt(add_svc)));

				rList.add(map);
			}
		}
		mav.addObject("list", rList);
		mav.addObject("mapCnts", service.pere700_1Q(vo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		return mav;
	}

	/**
	 * 입금처리
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere700T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "입금확인 되었습니다");

		service.pere700T(vo);

		return mav;
	}

	/**
	 * 환불요청현황
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere701Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl", "pere701Q.do");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		String selDt = "";
		String selDtTmp = "";

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime()) + "%");
		} else {
			selDt = vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt() + "%");
		}
		mav.addObject("selDtTmp", selDtTmp);
		if (selDt.length() == 6) {
			mav.addObject("selDt", selDt + "01");
		} else if (selDt.length() == 8) {
			mav.addObject("selDt", selDt);
		}

		if (null != vo.getSrc_val() && !"".equals(vo.getSrc_val())) {
			vo.setSrc_val("%" + vo.getSrc_val() + "%");
		}
		mav.addObject("mapCnts", service.pere700_1Q(vo));

		List list = service.pere701Q(vo);
		List rList = new ArrayList();

		if (list != null && 0 < list.size()) {
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				String data = (String) map.get("cancel_info");

				if (data == null || "".equals(data)) {
					map.put("room_nm", "서비스 삭제");
					rList.add(map);
					continue;
				}

				// 부가서비스 가격
				String add_svc = data.split("@")[0];

				String into = data.split("@")[1];
				int pay = 0;
				String room_nm = "";
				String reg_dt = "";
				String use_man_cnt = "";
				String use_cnt = "";
				String reservation_dt = "";
				String reservation_dt_tmp = "";
				String day_cnt = "";
				String total_pay = "";

				for (int j = 0; j < into.split(";").length; j++) {
					String[] vals = into.split(";")[j].split(":");
					// 입금대기자 정보(부가서비스
					// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if (j != 0) {
						room_nm += "</br>";
						reg_dt += "</br>";
						use_man_cnt += "</br>";
						use_cnt += "</br>";
						reservation_dt += "</br>";
						reservation_dt_tmp += "</br>";
						day_cnt += "</br>";
						total_pay += "</br>";
					}
					room_nm += vals[0];

					use_man_cnt += vals[2] + "/" + vals[3];

					String[] val4 = vals[4].split(",");
					for (int k = 0; k < val4.length; k++) {
						if (k == 0) {
							reservation_dt += val4[k].substring(4, 6) + "."
									+ val4[k].substring(6, 8);
						} else {
							if (val4[k - 1].substring(4, 6).equals(
									val4[k].substring(4, 6))) {
								reservation_dt += ", "
										+ val4[k].substring(6, 8);
							} else {
								reservation_dt += ", "
										+ val4[k - 1].substring(4, 6) + "."
										+ val4[k].substring(6, 8);
							}

						}
					}
					reservation_dt += "(" + vals[1].substring(2, 4) + "."
							+ vals[1].substring(4, 6) + "."
							+ vals[1].substring(6, 8) + ")";

					day_cnt += vals[5] + "박";
					total_pay += vals[6];

					pay += Integer.parseInt(vals[6]);
				}
				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				map.put("reservation_dt", reservation_dt);
				map.put("day_cnt", day_cnt);

				map.put("total_pay", (pay + Integer.parseInt(add_svc)));

				rList.add(map);
			}
		}
		mav.addObject("list", rList);
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		return mav;
	}

	/**
	 * 환불요청 조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere702Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		// 환불요금표
		Map refund = service.pere202_3Q(vo);

		// 객실예약정보 조회
		mav.addObject("list", service.pere702_1Q(vo));

		// 부가서비스 조회
		mav.addObject("rList", service.pere702_2Q(vo));

		// 예약자 환불정보 조회
		mav.addObject("map", service.pere702_3Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		return mav;
	}

	/**
	 * 환불금 입금처리
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere702T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "환불금 입금처리 되었습니다");

		// 환불금 처리
		service.pere702T(vo);

		return mav;
	}

	/**
	 * 종합취소현황
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere703Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl", "pere703Q.do");

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		String selDt = "";
		String selDtTmp = "";

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime()) + "%");
		} else {
			selDt = vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt() + "%");
		}
		mav.addObject("selDtTmp", selDtTmp);
		if (selDt.length() == 6) {
			mav.addObject("selDt", selDt + "01");
		} else if (selDt.length() == 8) {
			mav.addObject("selDt", selDt);
		}
		// 조회조건
		if (null != vo.getSrc_val() && !"".equals(vo.getSrc_val())) {
			vo.setSrc_val("%" + vo.getSrc_val() + "%");
		}

		// 종합취소 현황조회
		List list = service.pere703Q(vo);
		List rList = new ArrayList();

		if (list != null && 0 < list.size()) {
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				String data = (String) map.get("cancel_info");

				if (data == null || "".equals(data)) {
					map.put("room_nm", "서비스 삭제");
					rList.add(map);
					continue;
				}

				// 부가서비스 가격
				String add_svc = data.split("@")[0];

				String into = data.split("@")[1];
				int pay = 0;
				String room_nm = "";
				String reg_dt = "";
				String use_man_cnt = "";
				String use_cnt = "";
				String reservation_dt = "";
				String reservation_dt_tmp = "";
				String day_cnt = "";
				String total_pay = "";

				for (int j = 0; j < into.split(";").length; j++) {
					String[] vals = into.split(";")[j].split(":");
					// 입금대기자 정보(부가서비스
					// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if (j != 0) {
						room_nm += "</br>";
						reg_dt += "</br>";
						use_man_cnt += "</br>";
						use_cnt += "</br>";
						reservation_dt += "</br>";
						reservation_dt_tmp += "</br>";
						day_cnt += "</br>";
						total_pay += "</br>";
					}
					room_nm += vals[0];

					use_man_cnt += vals[2] + "/" + vals[3];

					String[] val4 = vals[4].split(",");
					for (int k = 0; k < val4.length; k++) {
						if (k == 0) {
							reservation_dt += val4[k].substring(4, 6) + "."
									+ val4[k].substring(6, 8);
						} else {
							if (val4[k - 1].substring(4, 6).equals(
									val4[k].substring(4, 6))) {
								reservation_dt += ", "
										+ val4[k].substring(6, 8);
							} else {
								reservation_dt += ", "
										+ val4[k - 1].substring(4, 6) + "."
										+ val4[k].substring(6, 8);
							}

						}
					}
					reservation_dt += "(" + vals[1].substring(2, 4) + "."
							+ vals[1].substring(4, 6) + "."
							+ vals[1].substring(6, 8) + ")";

					day_cnt += vals[5] + "박";
					total_pay += vals[6];

					pay += Integer.parseInt(vals[6]);
				}
				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				map.put("reservation_dt", reservation_dt);
				map.put("day_cnt", day_cnt);

				map.put("total_pay", (pay + Integer.parseInt(add_svc)));

				rList.add(map);
			}
		}
		mav.addObject("list", rList);

		mav.addObject("mapCnts", service.pere700_1Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		return mav;
	}

	/**
	 * 종합취소 미입금 취소 삭제 처리
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere703T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		String reservation_dt = vo.getReservation_dt() == null ? "" : vo
				.getReservation_dt();
		ModelAndView mav = new ModelAndView("redirect:./pere703Q.do?p_id="
				+ vo.getP_id() + "&reservation_dt=" + reservation_dt);
		service.pere703T(vo);
		return mav;
	}

	/**
	 * 예약종료 현황
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere704Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("pageUrl", "pere704Q.do");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		String selDt = "";
		String selDtTmp = "";

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			selDt = frmDate.format(d1.getTime());
			selDtTmp = frmDate.format(d1.getTime());
			vo.setReservation_dt(frmDate.format(d1.getTime()) + "%");
		} else {
			selDt = vo.getReservation_dt();
			selDtTmp = vo.getReservation_dt();
			vo.setReservation_dt(vo.getReservation_dt() + "%");
		}
		mav.addObject("selDtTmp", selDtTmp);
		if (selDt.length() == 6) {
			mav.addObject("selDt", selDt + "01");
		} else if (selDt.length() == 8) {
			mav.addObject("selDt", selDt);
		}
		// 조회조건
		if (null != vo.getSrc_val() && !"".equals(vo.getSrc_val())) {
			vo.setSrc_val("%" + vo.getSrc_val() + "%");
		}

		List list = service.pere704Q(vo);
		List rList = new ArrayList();

		if (list != null && 0 < list.size()) {
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				String data = (String) map.get("com_info");

				if (data == null || "".equals(data)) {
					map.put("room_nm", "서비스 삭제");
					rList.add(map);
					continue;
				}

				// 부가서비스 가격
				String add_svc = data.split("@")[0];

				String into = data.split("@")[1];
				int pay = 0;
				String room_nm = "";
				String reg_dt = "";
				String use_man_cnt = "";
				String use_cnt = "";
				String reservation_dt = "";
				String reservation_dt_tmp = "";
				String day_cnt = "";
				String total_pay = "";

				for (int j = 0; j < into.split(";").length; j++) {
					String[] vals = into.split(";")[j].split(":");
					// 입금대기자 정보(부가서비스
					// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...
					if (j != 0) {
						room_nm += "</br>";
						reg_dt += "</br>";
						use_man_cnt += "</br>";
						use_cnt += "</br>";
						reservation_dt += "</br>";
						reservation_dt_tmp += "</br>";
						day_cnt += "</br>";
						total_pay += "</br>";
					}
					room_nm += vals[0];
					use_man_cnt += vals[2] + "/" + vals[3];
					String[] val4 = vals[4].split(",");
					for (int k = 0; k < val4.length; k++) {
						if (k == 0) {
							reservation_dt += val4[k].substring(4, 6) + "."
									+ val4[k].substring(6, 8);
						} else {
							if (val4[k - 1].substring(4, 6).equals(
									val4[k].substring(4, 6))) {
								reservation_dt += ", "
										+ val4[k].substring(6, 8);
							} else {
								reservation_dt += ", "
										+ val4[k - 1].substring(4, 6) + "."
										+ val4[k].substring(6, 8);
							}

						}
					}
					reservation_dt += "(" + vals[1].substring(2, 4) + "."
							+ vals[1].substring(4, 6) + "."
							+ vals[1].substring(6, 8) + ")";

					day_cnt += vals[5] + "박";
					total_pay += vals[6];

					pay += Integer.parseInt(vals[6]);
				}

				map.put("add_svc", add_svc);
				map.put("room_nm", room_nm);
				map.put("reg_dt", reg_dt);
				map.put("use_man_cnt", use_man_cnt);
				// map.put("use_cnt", use_cnt);
				map.put("reservation_dt", reservation_dt);
				// map.put("reservation_end_dt", reservation_dt_tmp);
				map.put("day_cnt", day_cnt);

				map.put("total_pay", (pay + Integer.parseInt(add_svc)));

				rList.add(map);
			}
		}
		mav.addObject("list", rList);
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		mav.addObject("mapCnts", service.pere700_1Q(vo));
		return mav;
	}

	/**
	 * 예약완료자료 삭제
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere704T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		String reservation_dt = vo.getReservation_dt() == null ? "" : vo
				.getReservation_dt();
		ModelAndView mav = new ModelAndView("redirect:./pere704Q.do?p_id="
				+ vo.getP_id() + "&reservation_dt=" + reservation_dt);
		service.pere704T(vo);
		return mav;
	}

	/**
	 * 입금대기현황 상세
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere705Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		vo.setRm_status("R");

		List list = (List) service.pere705Q(vo);
		List returnList = new ArrayList();
		if (list != null && 0 < list.size()) {
			for (int i = 0; i < list.size(); i++) {
				Map data = (Map) list.get(i);
				//
				// data.put("dc_pay", 0);
				// data.put("pay", 0);

				returnList.add(data);
			}
		}

		//
		mav.addObject("list", returnList);
		mav.addObject("rtAddSvcList", service.pere705_1Q(vo));

		// 예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		return mav;
	}

	/**
	 * 예약취소(관리자)
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere705_1T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		boolean chkRelay = false;
		//연박 취소설정 체크 연박일 경우 하루만 취소 불가능하다
		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				List chkList = service.pere502_5Q(vo);

				if(chkList.size()>0){
					for (int ij = 0; ij < chkList.size() ; ij++) {
						Map relMap = (Map) chkList.get(ij);
						String chk_pm_dt = relMap.get("pm_dt").toString();
						String chk_p_id = relMap.get("p_id").toString();
						int chk_pr_no = Integer.parseInt(relMap.get("pr_no").toString());
						
						boolean chkRelYn = false;
						
						for (int ik = 0; ik < vo.getIdxs().length; ik++) {
							if(chk_pr_no == vo.getPr_nos()[vo.getIdxs()[ik]]
									&& chk_p_id.equals(vo.getP_id())
									&& chk_pm_dt.equals(vo.getReservation_dts()[vo.getIdxs()[ik]])
									){
								chkRelYn=true;
							}
							if(chkRelYn){
								break;
							}
						}
						if(!chkRelYn){
							chkRelay = true;
						}
						
					}	
				}
				if(chkRelay){
					break;
				}
			}
		}
		
		//chkRelay가 true면 연박삭제해야한다
		if(chkRelay){
			mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./pere705Q.do?p_id=" + vo.getP_id()+"&rm_no=" +vo.getRm_no());
			mav.addObject("msg", "연박설정이 있습니다 연박으로 예약한 자료는 모두 선하셔야 합니다");
			mav.addObject("historyBackYn", "Y");

			return mav;

		}
		
		
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "예약취소되었습니다");

		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				service.pere600_1T(vo);
				service.pere600_2T(vo);
			}
		}

		if (vo.getIdxs2() != null && 0 < vo.getIdxs2().length) {
			for (int i = 0; i < vo.getIdxs2().length; i++) {
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);
				service.pere502_3T(vo);
			}
		}

		Map sms_data = service.pere502_4Q(vo);

		// sms 보내기 시작
		// sms 보내기
		String data = (String) sms_data.get("r_info");

		String into = data.split("@")[1];
		int dayCnt = 0;
		String reservation_dt = "";
		String room_nm = "";

		for (int j = 0; j < into.split(";").length; j++) {
			String[] vals = into.split(";")[j].split(":");
			// 입금대기자 정보(부가서비스 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

			String[] val4 = vals[4].split(",");
			for (int k = 0; k < val4.length; k++) {
				dayCnt++;

				if (k == 0 && j == 0) {
					reservation_dt = val4[k].substring(0, 4) + "."
							+ val4[k].substring(4, 6) + "."
							+ val4[k].substring(6, 8);
					room_nm = vals[0];
					// if(into.split(";").length>1){
					// reservation_dt+=".";
					// room_nm+=".";
					// }
				}
			}
		}

		Map smsMap = service.pere1100Q(vo);
		SMSUtil smsUtil = new SMSUtil();
		
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		if("Y".equals(pensionInfo.get("sms_send_yn"))){
			int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
			
			if(chk_sms_cnt > 0){

				if ("Y".equals(smsMap.get("m1"))) {
					// 사용자에게 보내기
					// [펜션명]2009-00-00/객실명 예약취소완료
					StringBuffer msg = new StringBuffer();
					String send = sms_data.get("p_phone1") + "-"
							+ sms_data.get("p_phone2") + "-" + sms_data.get("p_phone3");
					String recive = (String) sms_data.get("r_phone1") + "-"
							+ (String) sms_data.get("r_phone2") + "-"
							+ (String) sms_data.get("r_phone3");
					msg.append("[");
					msg.append(sms_data.get("p_nm"));
					msg.append("] ");
					msg.append(reservation_dt);
					if (dayCnt > 1) {
						msg.append("외 ");
						msg.append((dayCnt - 1));
						msg.append("일");
					}
					msg.append("/");
					msg.append(room_nm);
					if (into.split(";").length > 1) {
						msg.append("외 ");
						msg.append((into.split(";").length - 1));
						msg.append("객실");
					}
					msg.append(" 예약취소 완료");

					String returnCode = smsUtil.send(send, recive,
							JspUtil.getByteSizeToString(msg.toString(), 80));
					// sms 히스토리에 넣기
					vo.setP_nm((String) sms_data.get("p_nm"));
					vo.setFrom_no(send);
					vo.setTo_no(recive);
					vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(), 80));
					vo.setC_code(returnCode);
					vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

					service.pere710Q(vo);
					if ("1".equals(returnCode)) {
						// sms 카운트 줄이기
						service.pere711Q(vo);
					}
				}
				if ("Y".equals(smsMap.get("m2"))) {
					// 관리자에게 보내기
					// [취소완료]2009-00-00/객실명/1박/아무개
					StringBuffer msg = new StringBuffer();
					String send = (String) sms_data.get("r_phone1") + "-"
							+ (String) sms_data.get("r_phone2") + "-"
							+ (String) sms_data.get("r_phone3");
					String recive = sms_data.get("p_phone1") + "-"
							+ sms_data.get("p_phone2") + "-" + sms_data.get("p_phone3");
					msg.append("[취소완료]");

					msg.append(reservation_dt);
					if (dayCnt > 1) {
						msg.append("외 ");
						msg.append((dayCnt - 1));
						msg.append("일");
					}
					msg.append("/");
					msg.append(room_nm);
					if (into.split(";").length > 1) {
						msg.append("외 ");
						msg.append((into.split(";").length - 1));
						msg.append("객실");
					}
					msg.append("/");
					msg.append(dayCnt);
					msg.append("박/");
					msg.append(sms_data.get("reservation_nm"));

					String returnCode = smsUtil.send(send, recive,
							JspUtil.getByteSizeToString(msg.toString(), 80));
					// sms 히스토리에 넣기
					vo.setP_nm((String) sms_data.get("p_nm"));
					vo.setFrom_no(send);
					vo.setTo_no(recive);
					vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(), 80));
					vo.setC_code(returnCode);
					vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

					service.pere710Q(vo);
					if ("1".equals(returnCode)) {
						// sms 카운트 줄이기
						service.pere711Q(vo);
					}
				}		
			}
		}
		return mav;
	}

	/**
	 * 입금처리
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere705_2T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "입금처리되었습니다");

		// List list = (List) service.pere705Q(vo);
		// long[] rm_nos = new long[list.size()];
		//
		//
		// if(list !=null && 0<list.size()){
		// for(int i=0; i < list.size();i++){
		//
		// Map data = (Map) list.get(i);
		// rm_nos[i]=Integer.parseInt(String.valueOf( data.get("rm_no")));
		//
		// }
		// vo.setRm_nos(rm_nos);
		// }

		service.pere700T(vo);

		return mav;
	}

	/**
	 * 대기시간 연장
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere705_3T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "대기시간 연장되었습니다");

		service.pere705_3T(vo);
		service.pere705_4T(vo);

		return mav;
	}

	/**
	 * sms 계좌 재전송
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere705_5T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();

		Map map = service.pere705_5Q(vo);

		StringBuffer msg = new StringBuffer();
		int totalPay = 0;

		String r_info = "";

		if ("".equals(map.get("r_info"))) {
			r_info = (String) map.get("c_info");
		} else {
			r_info = (String) map.get("r_info");
		}

		// 부가서비스 가격
		String add_svc = r_info.split("@")[0];
		String into = r_info.split("@")[1];
		int pay = 0;
		for (int j = 0; j < into.split(";").length; j++) {
			String[] vals = into.split(";")[j].split(":");
			pay += Integer.parseInt(vals[6]);
		}

		totalPay = (pay + Integer.parseInt(add_svc));

		// [펜션명]객실명-국민은행 142313-123-123132 100,000원
		// 30분후 예약이 자동삭제됩니다
		java.text.DecimalFormat decFormat = new java.text.DecimalFormat(
				"###,###,###,###");

		msg.append("[");
		msg.append(map.get("p_nm"));
		msg.append("] ");
		msg.append(map.get("room_nm"));
		msg.append("-");
		msg.append(map.get("send_bank"));
		msg.append(" ");
		msg.append(decFormat.format(totalPay));
		msg.append("원");
		msg.append("30분후 예약이 자동취소됩니다");
		SMSUtil smsUtil = new SMSUtil();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		if("Y".equals(pensionInfo.get("sms_send_yn"))){
			int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
			
			if(chk_sms_cnt > 0){

				// 사용자 sms 전송
				String send = map.get("p_tel1") + "" + map.get("p_tel2")
						+ map.get("p_tel3");
				String recive = map.get("r_phone1") + "" + map.get("r_phone2")
						+ map.get("r_phone3");

				String returnCode = smsUtil.send(send, recive, msg.toString());
				// sms 히스토리에 넣기
				vo.setP_nm((String) map.get("p_nm"));
				vo.setFrom_no(send);
				vo.setTo_no(recive);
				vo.setSms_content(msg.toString());
				vo.setC_code(returnCode);
				vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

				service.pere710Q(vo);
				if ("1".equals(returnCode)) {
					// sms 카운트 줄이기
					service.pere711Q(vo);
					jsonMap.put("sendYN", "Y");
				} else {
					jsonMap.put("sendYN", "N");
				}
			}
		}
		

		// jsonMap.put("", "");
		// jsonMap.put("", "");

		mav.addObject("map", jsonMap);

		return mav;
	}

	/**
	 * 입금확인 상세화면
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere706Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		vo.setRm_status("C");
		List list = service.pere705Q(vo);
		List returnList = new ArrayList();

		Calendar nowDate = Calendar.getInstance();// 오늘
		nowDate.set(Calendar.HOUR_OF_DAY, 1);
		nowDate.set(Calendar.MINUTE, 1);
		nowDate.set(Calendar.SECOND, 1);

		boolean cancelBtn = true;
		for (int i = 0; i < list.size(); i++) {
			Map map = (Map) list.get(i);
			Calendar reservationDt = Calendar.getInstance();// 오늘
			String reservation_dt = (String) map.get("reservation_dt");
			int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
			int mm = Integer.parseInt(reservation_dt.substring(4, 6));
			int dd = Integer.parseInt(reservation_dt.substring(6, 8));
			reservationDt.set(yyyy, mm - 1, dd, 1, 1, 1);

			if ((nowDate.getTime().getTime() - reservationDt.getTime()
					.getTime()) > 0) {
				map.put("cancelYN", "N");
			} else {
				cancelBtn = false;
				map.put("cancelYN", "Y");
			}
			returnList.add(map);
		}
		mav.addObject("list", returnList);
		mav.addObject("rtAddSvcList", service.pere705_1Q(vo));

		// 예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		COMAVo codeVo = new COMAVo();
		// 입금반환 은행
		codeVo.setCode_p_no("04");
		mav.addObject("codeList04", comaService.coma104Q(codeVo));
		mav.addObject("cancelBtn", cancelBtn);

		return mav;
	}

	/**
	 * 예약취소 환불요청으로 보냄(관리자)
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere706_1T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "예약취소 환불요청 되었습니다.");

		List pList = new ArrayList();
		List sList = new ArrayList();

		boolean chkRelay = false;
		//연박 취소설정 체크 연박일 경우 하루만 취소 불가능하다
		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				List chkList = service.pere502_5Q(vo);

				if(chkList.size()>0){
					for (int ij = 0; ij < chkList.size() ; ij++) {
						Map relMap = (Map) chkList.get(ij);
						String chk_pm_dt = relMap.get("pm_dt").toString();
						String chk_p_id = relMap.get("p_id").toString();
						int chk_pr_no = Integer.parseInt(relMap.get("pr_no").toString());
						
						boolean chkRelYn = false;
						
						for (int ik = 0; ik < vo.getIdxs().length; ik++) {
							if(chk_pr_no == vo.getPr_nos()[vo.getIdxs()[ik]]
									&& chk_p_id.equals(vo.getP_id())
									&& chk_pm_dt.equals(vo.getReservation_dts()[vo.getIdxs()[ik]])
									){
								chkRelYn=true;
							}
							if(chkRelYn){
								break;
							}
						}
						if(!chkRelYn){
							chkRelay = true;
						}
						
					}	
				}
				if(chkRelay){
					break;
				}
			}
		}
		
		//chkRelay가 true면 연박삭제해야한다
		if(chkRelay){
			mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./pere706Q.do?rm_no="+vo.getRm_no()+"&p_id=" + vo.getP_id());
			mav.addObject("msg", "연박설정이 있습니다 연박으로 예약한 자료는 모두 삭제하셔야 합니다");
			mav.addObject("historyBackYn", "Y");

			return mav;

		}
		
		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			for (int i = 0; i < vo.getIdxs().length; i++) {
				vo.setPr_no(vo.getPr_nos()[vo.getIdxs()[i]]);
				vo.setReservation_dt(vo.getReservation_dts()[vo.getIdxs()[i]]);
				Map pMap = service.pere502_1Q(vo);
				pList.add(pMap);
			}
		}
		if (vo.getIdxs2() != null && 0 < vo.getIdxs2().length) {
			for (int i = 0; i < vo.getIdxs2().length; i++) {
				vo.setAs_no(vo.getAs_nos()[vo.getIdxs2()[i]]);

				Map sMap = service.pere502_3Q(vo);
				sList.add(sMap);

			}
		}

		// 수수료
		int total_penalty_pay = 0;
		// 총 금액
		int total_pay = 0;

		Map refund = service.pere202_3Q(vo);
		// 취소할 예약 객실목록

		if (pList != null && 0 < pList.size()) {
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if (list != null && 0 < list.size()) {
				for (int i = 0; i < list.size(); i++) {
					Map data = (Map) list.get(i);
					vo.setReservation_dt((String) data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf(data
							.get("pr_no"))));
					total_pay += Integer.parseInt(String.valueOf(data
							.get("total_pay")));
					vo.setReg_dt((String) data.get("reg_dt"));
					int dateCha = Integer.parseInt(String.valueOf(data
							.get("dateCha")));
					if (dateCha < 0) {
						dateCha = 0;
					}
					if (dateCha > 7) {
						int penalty_pay = (Integer) data.get("total_pay");
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay += penalty_pay;
						vo.setPenalty_pay(penalty_pay);
					} else {
						int per = (Integer) refund.get("day_a_" + dateCha);
						int add_pay = (Integer) data.get("add_pay");
						data.put("per", per);
						int r_pay = Integer.parseInt(Long
								.toString((long) (((Integer) data
										.get("total_pay") - (Integer) data
										.get("add_pay")) * (per / 100.0))));
						// 절삭 처리
						r_pay = r_pay / 1000;
						r_pay = r_pay * 1000;
						int penalty_pay = (Integer) data.get("total_pay")
								- r_pay - add_pay;
						data.put("penalty_pay", penalty_pay);
						total_penalty_pay += r_pay + add_pay;
						vo.setPenalty_pay(penalty_pay);
					}

					// 데이터 환불요청 후 취소자료에 넣기
					// service.pere503_1T(vo);

				}
			}
			//
			// //예약객실 취소처리
			// vo.setNext_dates(pList);
			// //예약객실 삭제
			// service.pere503_2T(vo);
		}

		// 부가서비스 목록
		if (sList != null && 0 < sList.size()) {
			for (int i = 0; i < sList.size(); i++) {
				Map data = (Map) sList.get(i);
				total_penalty_pay += (Integer) data.get("total_pay");
				total_pay += Integer.parseInt(String.valueOf(data
						.get("total_pay")));
			}
			// vo.setNext_dates(sList);
			// service.pere503_3T(vo);

		}

		// 총 금액
		vo.setTotal_pay(total_pay);
		// 수수료
		vo.setPenalty_pay(total_penalty_pay);
		// 최종 환불요청 자료에 넣기
		vo.setRe_no(service.pere503_4T(vo));

		if (pList != null && 0 < pList.size()) {
			vo.setNext_dates(pList);
			List list = service.pere501_5Q(vo);
			List returnList = new ArrayList();
			if (list != null && 0 < list.size()) {
				for (int i = 0; i < list.size(); i++) {
					Map data = (Map) list.get(i);
					vo.setReservation_dt((String) data.get("reservation_dt"));
					vo.setPr_no(Integer.parseInt(String.valueOf(data
							.get("pr_no"))));
					int dateCha = Integer.parseInt(String.valueOf(data
							.get("dateCha")));
					if (dateCha < 0) {
						dateCha = 0;
					}

					int per = 100;
					if (dateCha > 7) {
						per = (Integer) refund.get("general");
					} else {
						per = (Integer) refund.get("day_a_" + dateCha);
					}
					int add_pay = (Integer) data.get("add_pay");
					// data.put("per", per);
					int r_pay = Integer
							.parseInt(Long.toString((long) (((Integer) data
									.get("total_pay") - (Integer) data
									.get("add_pay")) * (per / 100.0))));
					// 절삭 처리
					r_pay = r_pay / 1000;
					r_pay = r_pay * 1000;
					int penalty_pay = r_pay + add_pay;
					// data.put("penalty_pay", penalty_pay);
					// total_penalty_pay+= r_pay+add_pay;
					vo.setPenalty_per(per);
					vo.setPenalty_pay(penalty_pay);

					// 데이터 환불요청 후 취소자료에 넣기
					service.pere503_1T(vo);

				}
			}

			// 예약객실 취소처리
			vo.setNext_dates(pList);
			// 예약객실 삭제
			service.pere503_2T(vo);
		}

		// 부가서비스 목록
		if (sList != null && 0 < sList.size()) {
			vo.setNext_dates(sList);
			service.pere503_3T(vo);
		}

		List rm_nos = new ArrayList();
		for (int i = 0; i < pList.size(); i++) {
			Map data1 = (Map) pList.get(i);
			rm_nos.add(data1.get("rm_no"));
		}
		vo.setNext_dates(rm_nos);


		//연박살리기
		if (vo.getIdxs() != null && 0 < vo.getIdxs().length) {
			List relList = new ArrayList();
			for (int i = 0; i < vo.getIdxs().length; i++) {
				Map dt = new HashMap();
				
				dt.put("pr_no", vo.getPr_nos()[vo.getIdxs()[i]]);
				dt.put("reservation_dt", vo.getReservation_dts()[vo.getIdxs()[i]]);
				dt.put("p_id", vo.getP_id());
				
				List rdList =service.pere502_9Q(dt);
				for(int j=0; j < rdList.size();j++){
					Map rdMap = (Map) rdList.get(j);
					String rd = (String) rdMap.get("reservation_dt");
					if(rd != null &&  !"".equals(rd)){
						dt.put("reservation_dt", rd);
						service.pere502_10T(dt);
						
						service.pere502_7T(dt);	
					}	
				}
				
			}
		}
		
		// sms 보내기
		List smsList = service.pere700_2Q(vo);
		vo.setNext_dates(pList);

		Map smsMap = service.pere1100Q(vo);
		SMSUtil smsUtil = new SMSUtil();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		if (null != smsList && 0 < smsList.size()) {
			for (int i = 0; i < smsList.size(); i++) {
				Map map = (Map) smsList.get(i);

				// [펜션명]아무개님 예약취소 완료:50.000원 익일6시이내
				// 입금됩니다
				DecimalFormat decFormat = new java.text.DecimalFormat(
						"###,###,###,###");

				StringBuffer msg = new StringBuffer();
				msg.append("[");
				msg.append(pensionInfo.get("p_nm"));
				msg.append("] ");
				msg.append(map.get("reservation_nm"));
				msg.append("님 예약취소 완료 : ");
				msg.append(decFormat.format(vo.getTotal_pay()));
				msg.append("원 익일 6시이내 입금됩니다.");

				if("Y".equals(pensionInfo.get("sms_send_yn"))){
					int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
					
					if(chk_sms_cnt > 0){
						if ("Y".equals(smsMap.get("n1"))) {
							// 사용자에게 보내기

							String send = pensionInfo.get("p_phone1") + "-"
									+ pensionInfo.get("p_phone2") + "-"
									+ pensionInfo.get("p_phone3");
							String recive = map.get("r_phone1") + "-"
									+ map.get("r_phone2") + "-" + map.get("r_phone3");

							String returnCd = smsUtil.send(send, recive,
									JspUtil.getByteSizeToString(msg.toString(), 80));
							// sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm"));
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(
									msg.toString(), 80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

							service.pere710Q(vo);
							if ("1".equals(returnCd)) {
								service.pere711Q(vo);
							}
							// sms 히스토리에 넣기 종료
						}
						if ("Y".equals(smsMap.get("n2"))) {
							// 관리자에게 보내기
							String send = map.get("r_phone1") + "-"
									+ map.get("r_phone2") + "-" + map.get("r_phone3");
							String recive = pensionInfo.get("p_phone1") + "-"
									+ pensionInfo.get("p_phone2") + "-"
									+ pensionInfo.get("p_phone3");

							String returnCd = smsUtil.send(send, recive,
									JspUtil.getByteSizeToString(msg.toString(), 80));
							// sms 히스토리에 넣기
							vo.setP_nm((String) pensionInfo.get("p_nm"));
							vo.setFrom_no(send);
							vo.setTo_no(recive);
							vo.setSms_content(JspUtil.getByteSizeToString(
									msg.toString(), 80));
							vo.setC_code(returnCd);
							vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

							service.pere710Q(vo);
							if ("1".equals(returnCd)) {
								service.pere711Q(vo);
							}
						}
					}
				}
				
			}
		}
		// sms 보내기 끝

		return mav;
	}

	/**
	 * 예약대기 변경
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere706_2T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "예약대기 처리되었습니다");

		service.pere706_1T(vo);
		service.pere706_2T(vo);

		return mav;
	}

	/**
	 * 예약취소 예약자 번호로 예약취소하기(관리자 )
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView pere706_3T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		mav.addObject("redirect", "./pere700Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "예약취소 되었습니다.");

		if (!"C".equals(vo.getRm_status())) {
			vo.setRm_status("R");
		}

		if (vo.getRm_nos() != null && vo.getRm_nos().length > 0) {
			for (int jj = 0; jj < vo.getRm_nos().length; jj++) {

				vo.setRm_no(vo.getRm_nos()[jj]);

				List pList = new ArrayList();
				List sList = new ArrayList();

				boolean chkRefunds = false;

				List roomsList = service.pere706_3_1Q(vo);
				if (roomsList != null && 0 < roomsList.size()) {
					for (int i = 0; i < roomsList.size(); i++) {
						Map pMap = (Map) roomsList.get(i);
						String rm_status = (String) pMap.get("rm_status");
						if ("C".equals(rm_status)) {
							chkRefunds = true;
						}
						pList.add(pMap);
					}
				}

				List serviceList = service.pere706_3_2Q(vo);
				if (serviceList != null && 0 < serviceList.size()) {
					for (int i = 0; i < serviceList.size(); i++) {
						Map sMap = (Map) serviceList.get(i);

						sList.add(sMap);
					}
				}

				if (chkRefunds) {
					// 환불 객실취소
					// 수수료
					int total_penalty_pay = 0;
					// 총 금액
					int total_pay = 0;

					Map refund = service.pere202_3Q(vo);
					// 취소할 예약 객실목록

					if (pList != null && 0 < pList.size()) {
						vo.setNext_dates(pList);
						List list = service.pere501_5Q(vo);
						List returnList = new ArrayList();
						if (list != null && 0 < list.size()) {
							for (int i = 0; i < list.size(); i++) {
								Map data = (Map) list.get(i);
								vo.setReservation_dt((String) data
										.get("reservation_dt"));
								vo.setPr_no(Integer.parseInt(String
										.valueOf(data.get("pr_no"))));
								total_pay += Integer.parseInt(String
										.valueOf(data.get("total_pay")));
								int dateCha = Integer.parseInt(String
										.valueOf(data.get("dateCha")));
								if (dateCha < 0) {
									dateCha = 0;
								}
								if (dateCha > 7) {
									int penalty_pay = (Integer) data
											.get("total_pay");
									data.put("penalty_pay", penalty_pay);
									total_penalty_pay += penalty_pay;
									vo.setPenalty_pay(penalty_pay);
								} else {
									int per = (Integer) refund.get("day_a_"
											+ dateCha);
									int add_pay = (Integer) data.get("add_pay");
									data.put("per", per);
									int r_pay = Integer
											.parseInt(Long
													.toString((long) (((Integer) data
															.get("total_pay") - (Integer) data
															.get("add_pay")) * (per / 100.0))));
									// 절삭 처리
									r_pay = r_pay / 1000;
									r_pay = r_pay * 1000;
									int penalty_pay = (Integer) data
											.get("total_pay") - r_pay - add_pay;
									data.put("penalty_pay", penalty_pay);
									total_penalty_pay += r_pay + add_pay;
									vo.setPenalty_pay(penalty_pay);
								}

								// 데이터 환불요청 후 취소자료에 넣기
								// service.pere503_1T(vo);

							}
						}
						//
						// //예약객실 취소처리
						// vo.setNext_dates(pList);
						// //예약객실 삭제
						// service.pere503_2T(vo);
					}

					// 부가서비스 목록
					if (sList != null && 0 < sList.size()) {
						for (int i = 0; i < sList.size(); i++) {
							Map data = (Map) sList.get(i);
							String as_status = (String) data.get("as_status");
							if ("C".equals(as_status)) {
								total_penalty_pay += (Integer) data
										.get("total_pay");
								total_pay += Integer.parseInt(String
										.valueOf(data.get("total_pay")));
							}
						}
					}

					// 총 금액
					vo.setTotal_pay(total_pay);
					// 수수료
					vo.setPenalty_pay(total_penalty_pay);
					// 최종 환불요청 자료에 넣기
					vo.setRe_no(service.pere503_4T(vo));

					if (pList != null && 0 < pList.size()) {
						vo.setNext_dates(pList);
						List list = service.pere501_5Q(vo);
						List returnList = new ArrayList();
						if (list != null && 0 < list.size()) {
							for (int i = 0; i < list.size(); i++) {
								Map data = (Map) list.get(i);
								vo.setReservation_dt((String) data
										.get("reservation_dt"));
								vo.setPr_no(Integer.parseInt(String
										.valueOf(data.get("pr_no"))));
								int dateCha = Integer.parseInt(String
										.valueOf(data.get("dateCha")));
								if (dateCha < 0) {
									dateCha = 0;
								}

								int per = 100;
								if (dateCha > 7) {
									per = (Integer) refund.get("general");
								} else {
									per = (Integer) refund.get("day_a_"
											+ dateCha);
								}
								int add_pay = (Integer) data.get("add_pay");
								// data.put("per", per);
								int r_pay = Integer
										.parseInt(Long
												.toString((long) (((Integer) data
														.get("total_pay") - (Integer) data
														.get("add_pay")) * (per / 100.0))));
								// 절삭 처리
								r_pay = r_pay / 1000;
								r_pay = r_pay * 1000;
								int penalty_pay = r_pay + add_pay;
								vo.setPenalty_per(per);
								vo.setPenalty_pay(penalty_pay);

								// 데이터 환불요청 후 취소자료에 넣기
								service.pere503_1T(vo);

							}
						}
						// 예약객실 취소처리
						vo.setNext_dates(pList);
						// 예약객실 삭제
						service.pere503_2T(vo);
					}

					// 부가서비스 목록
					if (sList != null && 0 < sList.size()) {
						vo.setNext_dates(sList);
						service.pere503_3T(vo);
					}
				} else {
					// 미입금 객실 취소
					Map sms_data = service.pere706_3_3Q(vo);
					// 자료를 옮기고 취소처리한다.
					if (pList != null && 0 < pList.size()) {
						for (int i = 0; i < pList.size(); i++) {
							Map data = (Map) pList.get(i);

							vo.setPr_no((Integer) data.get("pr_no"));
							vo.setReservation_dt((String) data
									.get("reservation_dt"));
							service.pere600_1T(vo);
							service.pere600_2T(vo);
						}
					}

					if (sList != null && 0 < sList.size()) {
						for (int i = 0; i < sList.size(); i++) {
							Map data = (Map) sList.get(i);

							vo.setAs_no((Integer) data.get("as_no"));
							service.pere502_3T(vo);
						}
					}
					
					//연박살리기
					if (pList != null && 0 < pList.size()) {
						for (int i = 0; i < pList.size(); i++) {
							Map data = (Map) pList.get(i);
							Map dt = new HashMap();
							
							dt.put("pr_no", data.get("pr_no"));
							dt.put("reservation_dt", data
									.get("reservation_dt"));
							dt.put("p_id", vo.getP_id());
							
							List rdList =service.pere502_9Q(dt);
							for(int j=0; j < rdList.size();j++){
								Map rdMap = (Map) rdList.get(j);
								String rd = (String) rdMap.get("reservation_dt");
								if(rd != null &&  !"".equals(rd)){
									dt.put("reservation_dt", rd);
									service.pere502_10T(dt);
									
									service.pere502_7T(dt);	
								}	
							}

						}
					}
					

					// sms 보내기
					String data = (String) sms_data.get("r_info");

					String into = data.split("@")[1];
					int dayCnt = 0;
					String reservation_dt = "";
					String room_nm = "";

					for (int j = 0; j < into.split(";").length; j++) {
						String[] vals = into.split(";")[j].split(":");
						// 입금대기자 정보(부가서비스
						// 가격@객실명:예약일자:기준사람:예약사람:이용일,이용일,...:이용기간:요금;...);...

						String[] val4 = vals[4].split(",");
						for (int k = 0; k < val4.length; k++) {
							dayCnt++;

							if (k == 0 && j == 0) {
								reservation_dt = val4[k].substring(0, 4) + "."
										+ val4[k].substring(4, 6) + "."
										+ val4[k].substring(6, 8);
								room_nm = vals[0];
								// if(into.split(";").length>1){
								// reservation_dt+=".";
								// room_nm+=".";
								// }
							}
						}
					}

					Map smsMap = service.pere1100Q(vo);
					SMSUtil smsUtil = new SMSUtil();
					
					PETIVo petiVo = new PETIVo();
					petiVo.setP_id(vo.getP_id());
					Map pensionInfo = petiService.peti300Q(petiVo);
					if("Y".equals(pensionInfo.get("sms_send_yn"))){
						int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
						
						if(chk_sms_cnt > 0){

							
							if ("Y".equals(smsMap.get("m1"))) {
								// 사용자에게 보내기
								// [펜션명]2009-00-00/객실명 예약취소완료
								StringBuffer msg = new StringBuffer();
								String send = sms_data.get("p_phone1") + "-"
										+ sms_data.get("p_phone2") + "-"
										+ sms_data.get("p_phone3");
								String recive = (String) sms_data.get("r_phone1") + "-"
										+ (String) sms_data.get("r_phone2") + "-"
										+ (String) sms_data.get("r_phone3");
								msg.append("[");
								msg.append(sms_data.get("p_nm"));
								msg.append("] ");
								msg.append(reservation_dt);
								if (dayCnt > 1) {
									msg.append("외 ");
									msg.append((dayCnt - 1));
									msg.append("일");
								}
								msg.append("/");
								msg.append(room_nm);
								if (into.split(";").length > 1) {
									msg.append("외 ");
									msg.append((into.split(";").length - 1));
									msg.append("객실");
								}
								msg.append(" 예약취소 완료");

								String returnCode = smsUtil
										.send(send,
												recive,
												JspUtil.getByteSizeToString(
														msg.toString(), 80));
								// sms 히스토리에 넣기
								vo.setP_nm((String) sms_data.get("p_nm"));
								vo.setFrom_no(send);
								vo.setTo_no(recive);
								vo.setSms_content(JspUtil.getByteSizeToString(
										msg.toString(), 80));
								vo.setC_code(returnCode);
								vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

								service.pere710Q(vo);
								if ("1".equals(returnCode)) {
									// sms 카운트 줄이기
									service.pere711Q(vo);
								}
							}
							if ("Y".equals(smsMap.get("m2"))) {
								// 관리자에게 보내기
								// [취소완료]2009-00-00/객실명/1박/아무개
								StringBuffer msg = new StringBuffer();
								String send = (String) sms_data.get("r_phone1") + "-"
										+ (String) sms_data.get("r_phone2") + "-"
										+ (String) sms_data.get("r_phone3");
								String recive = sms_data.get("p_phone1") + "-"
										+ sms_data.get("p_phone2") + "-"
										+ sms_data.get("p_phone3");
								msg.append("[취소완료]");

								msg.append(reservation_dt);
								if (dayCnt > 1) {
									msg.append("외 ");
									msg.append((dayCnt - 1));
									msg.append("일");
								}
								msg.append("/");
								msg.append(room_nm);
								if (into.split(";").length > 1) {
									msg.append("외 ");
									msg.append((into.split(";").length - 1));
									msg.append("객실");
								}
								msg.append(dayCnt);
								msg.append("/");
								msg.append(sms_data.get("reservation_nm"));

								String returnCode = smsUtil
										.send(send,
												recive,
												JspUtil.getByteSizeToString(
														msg.toString(), 80));
								// sms 히스토리에 넣기
								vo.setP_nm((String) sms_data.get("p_nm"));
								vo.setFrom_no(send);
								vo.setTo_no(recive);
								vo.setSms_content(JspUtil.getByteSizeToString(
										msg.toString(), 80));
								vo.setC_code(returnCode);
								vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

								service.pere710Q(vo);
								if ("1".equals(returnCode)) {
									// sms 카운트 줄이기
									service.pere711Q(vo);
								}
							}
						}
					}
				}
			}
		}

		return mav;
	}

	/**
	 * 종합취소 현황 상세조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere707Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		List rList = service.pere707_1Q(vo);
		mav.addObject("list", rList);
		mav.addObject("rtAddSvcList", service.pere707_2Q(vo));

		// 예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘
		int nowDt = Integer.parseInt(frmDatedd.format(d1.getTime().getTime()));
		boolean recovery = false;
		// 예약복구 처리 쿼리
		if (rList != null && 0 < rList.size()) {
			for (int i = 0; i < rList.size(); i++) {
				Map dt = (Map) rList.get(i);
				int chkDate = Integer.parseInt((String) dt
						.get("reservation_dt"));
				if (nowDt <= chkDate) {
					recovery = true;
				} else {
					recovery = false;
					break;
				}
			}
			// 예약이 되어있는지 확인
			if (recovery) {
				vo.setNext_dates(rList);
				int cnt = service.pere707Q(vo);
				if (cnt > 0) {
					recovery = false;
				}
			}

			if (recovery) {
				mav.addObject("recoveryYN", "Y");
			}
		}

		return mav;
	}

	/**
	 * 예약종료 현황 상세조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere708Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		vo.setRm_status("C");

		mav.addObject("list", service.pere705Q(vo));
		mav.addObject("rtAddSvcList", service.pere705_1Q(vo));

		// 예약자 정보
		mav.addObject("reservationInfo", service.pere705_2Q(vo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		COMAVo codeVo = new COMAVo();
		// 입금반환 은행
		codeVo.setCode_p_no("04");
		mav.addObject("codeList04", comaService.coma104Q(codeVo));

		return mav;
	}

	/**
	 * 예약통계
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere800Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		SimpleDateFormat frmDateNow = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyy");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("MM");
		SimpleDateFormat frmDateYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘
		Calendar d2 = Calendar.getInstance();// 오늘

		String selDt = vo.getReservation_dt();
		if (selDt.length() == 6) {
			mav.addObject("selDt", selDt + "01");
		} else if (selDt.length() == 4) {
			mav.addObject("selDt", selDt + frmDate1.format(d1.getTime()) + "01");
		} else {
			mav.addObject("selDt", selDt);
		}

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDateNow.format(d1.getTime()) + "%");
		}

		if ("1".equals(vo.getSrc_type())) {
			// 몇주검색할껀지 조건
			// 주간통계

			SimpleDateFormat frmW = new SimpleDateFormat("W");

			// 조회 날짜구하기
			Calendar dt_cal = Calendar.getInstance();// 오늘
			int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
			int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
			int dd = 1;

			dt_cal.set(yyyy, mm, dd);

			int lastDay = dt_cal.getActualMaximum(Calendar.DAY_OF_MONTH);
			List nList = new ArrayList();

			for (int i = 1; i <= lastDay; i++) {
				dt_cal.set(yyyy, mm, i);// 지정일.
				if (frmW.format(dt_cal.getTime()).equals(vo.getSrc_week())) {
					nList.add(frmDateYYYYMMDD.format(dt_cal.getTime()));
				}
			}
			String dates = ((String) nList.get(0)).substring(0, 4) + "-"
					+ ((String) nList.get(0)).substring(4, 6) + "-"
					+ ((String) nList.get(0)).substring(6, 8);
			dates += " ~ "
					+ ((String) nList.get(nList.size() - 1)).substring(0, 4)
					+ "-"
					+ ((String) nList.get(nList.size() - 1)).substring(4, 6)
					+ "-"
					+ ((String) nList.get(nList.size() - 1)).substring(6, 8);

			vo.setNext_dates(nList);
			mav.addObject("list", service.pere800_1Q(vo));
			mav.addObject("title",
					vo.getReservation_dt().substring(0, 4) + "년 "
							+ vo.getReservation_dt().substring(4, 6) + "월 "
							+ vo.getSrc_week() + "주 : " + dates);
		} else if ("2".equals(vo.getSrc_type())) {
			// 월간통계

			// 조회 날짜구하기
			Calendar dt_cal = Calendar.getInstance();// 오늘
			int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
			int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
			int dd = 1;

			dt_cal.set(yyyy, mm, dd);

			int lastDay = dt_cal.getActualMaximum(Calendar.DAY_OF_MONTH);
			List nList = new ArrayList();

			for (int i = 1; i <= lastDay; i++) {
				dt_cal.set(yyyy, mm, i);// 지정일.
				nList.add(frmDateYYYYMMDD.format(dt_cal.getTime()));
			}
			vo.setNext_dates(nList);
			vo.setReservation_dt(vo.getReservation_dt() + "%");
			mav.addObject("map", service.pere800_2Q(vo));
			mav.addObject("list", service.pere800_3Q(vo));
			mav.addObject("title", vo.getReservation_dt().substring(0, 4)
					+ "년 " + vo.getReservation_dt().substring(4, 6) + "월 ");
		} else if ("3".equals(vo.getSrc_type())) {
			List nList = new ArrayList();

			for (int i = 1; i <= 12; i++) {
				String m = Integer.toString(i);
				if (i < 10) {
					m = "0" + m;
				}

				nList.add(vo.getReservation_dt() + m + "%");
			}
			vo.setNext_dates(nList);
			vo.setReservation_dt(vo.getReservation_dt() + "%");
			mav.addObject("list1", service.pere800_4Q(vo));

			mav.addObject("list2", service.pere800_5Q(vo));
		}

		mav.addObject("startYYYY", 2012);
		mav.addObject("curYYYY", frmDate.format(d1.getTime()));
		mav.addObject("curMM", frmDate1.format(d1.getTime()));

		d2.add(Calendar.YEAR, 1);
		mav.addObject("endYYYY", frmDate.format(d2.getTime()));

		// 객실정보
		mav.addObject("rooms", service.pere101Q(vo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		return mav;
	}

	/**
	 * 팝업로그인
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere900POP(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView();

		return mav;
	}

	/**
	 * 펜션주 로그인 세션 등록
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere901Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("/common/close");

		Map usrInfo = service.pere901Q(vo);

		if (null == usrInfo) {
			// 로그인 자료가 없을때
			// ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./pere900Q.do?p_id=" + vo.getChk_p_id());
			mav.addObject("msg", "아이디 또는 비밀번호가 틀립니다.");

		} else {
			// 로그인 성공시
			req.getSession().setAttribute("userInfo", usrInfo);

			mav.addObject("parentRedirect",
					"./petc1001Q.do?p_id=" + vo.getChk_p_id());
			mav.addObject("closeYN", "Y");
		}

		return mav;
	}

	/**
	 * 로그아웃
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere902Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		ModelAndView mav = new ModelAndView("/common/close");

		// req.getSession().invalidate();
		req.getSession().removeAttribute("userInfo");
		req.getSession().removeAttribute("smsChk");

		mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());

		return mav;
	}

	/**
	 * 관리자 예약
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1000Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("serviceList", service.pere200Q(vo));

		COMAVo codeVo = new COMAVo();
		// 전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List", comaService.coma104Q(codeVo));
		// 이메일
		codeVo.setCode_p_no("03");
		mav.addObject("code2List", comaService.coma104Q(codeVo));

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		List aList = petiService.peti300_1Q(petiVo);

		List aList1 = new ArrayList();
		List aList2 = new ArrayList();
		List aList3 = new ArrayList();
		List aList4 = new ArrayList();

		if (aList != null && 0 < aList.size()) {
			for (int i = 0; i < aList.size(); i++) {
				Map map = (Map) aList.get(i);
				if ("1".equals(map.get("paa_type"))) {
					// 계좌
					aList1.add(map);
				} else if ("2".equals(map.get("paa_type"))) {
					// 픽업장소
					aList2.add(map);
				} else if ("3".equals(map.get("paa_type"))) {
					// 픽업정보
					aList3.add(map);
				} else if ("4".equals(map.get("paa_type"))) {
					// 도착시간
					aList4.add(map);
				}
			}
		}
		mav.addObject("aList1", aList1);
		mav.addObject("aList2", aList2);
		mav.addObject("aList3", aList3);
		mav.addObject("aList4", aList4);

		return mav;
	}

	/**
	 * 관리자예약하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1001T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		vo.setAdd_type("A");
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");
		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();

		// sms 방명, 숙박일, 등록일
		String smsRoom_nm = "";
		String smsReservation_dt = "";
		String smsReg_dt = "";

		int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
		int mm = Integer.parseInt(reservation_dt.substring(4, 6)) - 1;
		int dd = Integer.parseInt(reservation_dt.substring(6, 8));

		int totalPay = 0;

		int totalPayD1 = 0;
		int totalPayD2 = 0;
		int addPay = 0;
		// 시작일시 저장 sms
		String startDate = "";
		String startRooms = "";
		// sms 보낼때 몇박인지
		int bak = 0;
		List returnList = new ArrayList();

		vo.setP_id(p_id);

		// 펜션 요금 조회
		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {

			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];

			vo.setPr_no(pr_no);
			Map payInfo = service.pere202_1Q(vo);

			List nextDates = new ArrayList();

			// 연속된 방의 가격 다시 구하기
			for (int j = 0; j < rsv_days; j++) {
				bak++;
				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d1 = Calendar.getInstance();// 오늘

				d1.set(yyyy, mm, dd);// 지정일.
				d1.add(Calendar.DATE, j);
				//     //요일 출력.

				SimpleDateFormat weekday222 = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);
				SimpleDateFormat weekday = new SimpleDateFormat("EEE",
						java.util.Locale.KOREAN);

				nextDates.add(frmDate.format(d1.getTime()));
			}
			vo.setNext_dates(nextDates);
			List pList = service.pere202_2Q(vo);

			for (int j = 0; j < pList.size(); j++) {
				Map map = (Map) pList.get(j);
				String pm_dt = (String) map.get("pm_dt");

				// 해당 날짜
				String aa = (String) map.get("aa");
				Map returnMap = new HashMap();
				returnMap.put("reservation_dt", aa);
				if (i == 0) {
					startDate = aa.substring(0, 4) + "-" + aa.substring(4, 6)
							+ "-" + aa.substring(6, 8);
					startRooms = (String) payInfo.get("room_nm");
				}

				// sms 관련 정보
				if (i == 0 && j == 0) {
					SimpleDateFormat weekday222 = new SimpleDateFormat(
							"yyyy-MM-dd");
					smsRoom_nm = startRooms;
					smsReservation_dt = startDate;
					Calendar d11 = Calendar.getInstance();// 오늘
					smsReg_dt = weekday222.format(d11.getTime());
					if (vo.getPr_no_cnts().length > 1) {
						smsRoom_nm = startRooms;
						smsReservation_dt = startDate;
					} else if (rsv_days > 1) {
						smsReservation_dt = startDate;
					}
				}

				returnMap.put("pr_no", pr_no);
				returnMap.put("rowspan", pList.size());
				returnMap.put("man_cnt", man_cnt);
				returnMap.put("chi_cnt", chi_cnt);
				returnMap.put("room_nm", payInfo.get("room_nm"));
				int add_usr_pay = (Integer) payInfo.get("add_usr_pay");
				int add_child_pay = (Integer) payInfo.get("add_child_pay");

				returnMap.put("add_usr_pay", add_usr_pay);

				int totalMan = man_cnt + chi_cnt;
				returnMap.put("totalMan", totalMan);
				returnMap.put("use_man_cnt", payInfo.get("use_man_cnt"));
				// 인원수에 따른 가격 설정
				int use_man_cnt = (Integer) payInfo.get("use_man_cnt");

				int aCnt = man_cnt - use_man_cnt;

				// 추가비용
				int addPay_new = 0;

				if (aCnt < 0) {
					addPay_new += (add_child_pay + aCnt) * add_child_pay * 1000;
				} else {
					addPay_new += aCnt * add_usr_pay * 1000;
					addPay_new += chi_cnt * add_child_pay * 1000;
				}

				int pay_man = totalMan - (aCnt + chi_cnt);
				if (pay_man < 0) {
					pay_man = 0;
				}
				returnMap.put("pay_man", aCnt + chi_cnt);
				int pay_man_m = addPay_new;
				returnMap.put("pay_man_m", pay_man_m);
				addPay += pay_man_m;
				totalPay += pay_man_m;
				// 인원수에 따른 가격 설정 끝

				SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
				Calendar d11 = Calendar.getInstance();// 오늘

				returnMap.put("nowdt", frmDate.format(d11.getTime()));

				if (null != pm_dt && !"".equals(pm_dt)) {
					// 설정된 값이 있을때
					int pm_pay = Integer.parseInt(String.valueOf(map
							.get("o_pm_pay")));
					returnMap.put("pay", pm_pay);
					int pm_per = Integer.parseInt(String.valueOf(map
							.get("pm_per")));
					int pm_dc_m = Integer.parseInt(String.valueOf(map
							.get("pm_dc_m")));

					if (pm_per != 0 || pm_dc_m != 0) {
						int dc_pay = Integer.parseInt(String.valueOf(map
								.get("o_pm_pay")))
								- Integer.parseInt(String.valueOf(map
										.get("pm_pay")));
						returnMap.put("dc_pay", dc_pay);
						totalPay -= dc_pay;
						totalPayD1 -= dc_pay;
					} else {
						returnMap.put("dc_pay", 0);
					}

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				} else {
					// 설정된 값이 없을때 기본값

					int yyyy1 = Integer.parseInt(aa.substring(0, 4));
					int mm1 = Integer.parseInt(aa.substring(4, 6)) - 1;
					int dd1 = Integer.parseInt(aa.substring(6, 8));

					Calendar d1 = Calendar.getInstance();// 오늘

					d1.set(yyyy1, mm1, dd1);// 지정일.
					//     //요일 출력.
					SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
							java.util.Locale.KOREAN);
					String dayOfTheWeek = weekday2.format(d1.getTime());

					int pm_pay = 0;
					if ("일".equals(dayOfTheWeek) || "월".equals(dayOfTheWeek)
							|| "화".equals(dayOfTheWeek)
							|| "수".equals(dayOfTheWeek)
							|| "목".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_base") * 1000;
					} else if ("금".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_fri") * 1000;
					} else if ("토".equals(dayOfTheWeek)) {
						pm_pay = (Integer) payInfo.get("busy_1_sat") * 1000;
					}
					returnMap.put("dc_pay", 0);
					returnMap.put("pay", pm_pay);

					totalPay += pm_pay;
					totalPayD1 += pm_pay;
				}

				returnList.add(returnMap);
			}
		}

		// 객식 총 가격
		// totalPayD1 = totalPay;

		List rtAddSvcList = new ArrayList();
		// 부가서비스 가격 조회
		if (vo.getAs_no_idxs() != null && vo.getAs_no_idxs().length > 0) {
			List addServiceList = service.pere200Q(vo);
			for (int i = 0; i < vo.getAs_no_idxs().length; i++) {
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];

				for (int jj = 0; jj < addServiceList.size(); jj++) {
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if (mAs_no == as_no) {
						int as_pay = (Integer) map.get("as_pay");

						map.put("as_no", mAs_no);
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt * as_pay));
						map.put("reg_msg", req_msg);
						rtAddSvcList.add(map);
						totalPayD2 += use_cnt * as_pay;
						break;
					}
				}
			}
		}
		totalPay += totalPayD2;

		Map pensionInfo = service.pere203Q(vo);

		Calendar chkDt = Calendar.getInstance();// 오늘

		int tm = (Integer) pensionInfo.get("wait_time");
		chkDt.add(Calendar.HOUR, tm);

		SimpleDateFormat frmChkDt = new SimpleDateFormat("yyyyMMddHHmmss");

		vo.setRm_wait_time(frmChkDt.format(chkDt.getTime()));

		Map data = new HashMap();
		data.put("paramMap", vo);
		data.put("list", returnList);
		// 부가서비스 리턴
		data.put("rtAddSvcList", rtAddSvcList);

		// 예약한 객실 수
		data.put("smsRoomCnt", vo.getPr_no_cnts().length);
		// 총 가격
//		data.put("totalPay", totalPay);
		// 객실명
		data.put("smsRoom_nm", smsRoom_nm);
		// 예약일
		data.put("smsReservation_dt", smsReservation_dt);
		// 등록일
		data.put("smsReg_dt", smsReg_dt);
		// 숙박일
		data.put("smsBak", bak);
		// 데이터 저장
		
		int rrr_pay = 0;
		List list = new ArrayList();

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();
		String pg_no = vo.getPg_no();
		
		
		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {
			d1.set(yyyy, mm, dd);// 지정일.

			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int man_cnt = (int) vo.getMan_cnts()[vo.getPr_no_cnts()[i]];
			int chi_cnt = (int) vo.getChi_cnts()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];

			for (int j = 0; j < rsv_days; j++) {
				Map map = new HashMap();
				map.put("pr_no", pr_no);
				if (j != 0) {
					d1.add(Calendar.DATE, 1);
				}
				map.put("man_cnt", man_cnt);
				map.put("chi_cnt", chi_cnt);
				map.put("p_id", vo.getP_id());
				map.put("dy", d1.get(Calendar.DAY_OF_WEEK));
				map.put("reservation_dt", frmDate.format(d1.getTime()));

				list.add(map);
			}
		}
		
		PEREVo pvo = new PEREVo();
		pvo.setNext_dates(list);
		List relayList = service.pere200_4Q(pvo);
		
		String sPmDt = "";
		int sPrNo = 0;
		String sReservationDt = "";
		Boolean bChkrr = false;
		int mRrrPay=0;
		for(int i = 0;i < relayList.size();i++){
			Map rrData = (Map) relayList.get(i);
			
			String mPmDt = rrData.get("pm_dt").toString();
			int mPrNo = Integer.parseInt(rrData.get("pr_no").toString());
			String mReservationDt = rrData.get("reservation_dt").toString();
			
			
			if(sReservationDt.equals(mReservationDt) && mPrNo == sPrNo){
				
			}else{
				
				if(bChkrr){
					rrr_pay +=mRrrPay;
				}
				bChkrr = false;
			}
			mRrrPay = Integer.parseInt(rrData.get("rrr_pay").toString());
			sReservationDt = mReservationDt;
			sPrNo = mPrNo;
			
			Boolean mChkrr =false;
			for(int j = 0; j < list.size();j++){
				Map lData = (Map) list.get(j);
				int lPrNo = Integer.parseInt(lData.get("pr_no").toString());
				String lReservationDt = lData.get("reservation_dt").toString();

				
				
				if(lPrNo == mPrNo
						&& lReservationDt.equals(mPmDt)
						){
					bChkrr = true;
					mChkrr = true;
					break;
				}
			}
			if(!mChkrr){
				bChkrr = false;
			}
			
		}
		if(bChkrr){
			rrr_pay +=mRrrPay;
		}
//		연박할인 금액
		data.put("rrr_pay", rrr_pay);
		data.put("totalPay", totalPay-rrr_pay);
		
		service.pere204T(data);

		// int totalPay =
		// vo.get("totalPay")==null?1:(Integer)vo.get("totalPay");
		// String smsRoom_nm = (String) vo.get("smsRoom_nm");
		// String smsReservation_dt = (String) vo.get("smsReservation_dt");
		// int smsBak = vo.get("smsBak")==null?1:(Integer)vo.get("smsBak");
		// sms 보내기
		Map smsMap = service.pere1100Q(vo);
		SMSUtil smsUtil = new SMSUtil();

		mav.setViewName("/common/close");
		mav.addObject("redirect", "./pere1000Q.do?p_id=" + vo.getP_id()
				+ "&reservation_dt=" + reservation_dt);
		mav.addObject("msg", "예약되었습니다");

		return mav;
	}

	/**
	 * sms 휴대폰 관리
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1100Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("map", service.pere1100Q(vo));
		// mav.addObject("list", service.pere1100_2Q(vo));
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		mav.addObject("list", petiService.peti600Q(petiVo));
		mav.addObject("mapA", petiService.peti301Q(petiVo));

		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);

		return mav;
	}

	/**
	 * sms 환경 변경
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1101T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");

		mav.addObject("redirect", "./pere1100Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "수정되었습니다");

		service.pere1101T(vo);
		return mav;
	}

	public static void main(String[] args) throws UnsupportedEncodingException {
		// TODO Auto-generated method stub
		Calendar today = Calendar.getInstance();
		System.out.println("이 해의 년도 : " + today.get(Calendar.YEAR));
		System.out.println("월 (0~11, 0:1월)" + today.get(Calendar.MONTH));
		System.out.println("이 해의 몇 째 주 : " + today.get(Calendar.WEEK_OF_YEAR));
		System.out.println("이 달의 몇 째 주 : " + today.get(Calendar.WEEK_OF_MONTH));

		// DATE와 DAY_OF MONTH는 같다.

		System.out.println("이 달의 몇 일 : " + today.get(Calendar.DATE));
		System.out.println("이 달의 몇 일 : " + today.get(Calendar.DAY_OF_MONTH));
		System.out.println("이 해의 몇 일: " + today.get(Calendar.DAY_OF_YEAR));
		System.out.println("요일(1~7, 1 : 일요일) : "
				+ today.get(Calendar.DAY_OF_WEEK)); // 1:일요일, 2... 7:토요일
		System.out.println("이 달의 몇 째 요일 : "
				+ today.get(Calendar.DAY_OF_WEEK_IN_MONTH));
		System.out.println("오전_오후(0:오전, 1:오후) : " + today.get(Calendar.AM_PM));
		System.out.println("시간(0~11) : " + today.get(Calendar.HOUR));
		System.out.println("시간(0~23 : " + today.get(Calendar.HOUR_OF_DAY));
		System.out.println("분(0~59) : " + today.get(Calendar.MINUTE));
		System.out.println("초(0~59) : " + today.get(Calendar.SECOND));
		System.out.println("1000분의 1초 (0~999) : "
				+ today.get(Calendar.MILLISECOND));

	}

	/**
	 * 관리자 예약현황
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1200Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));

		// 이전달 조회 금지
		// if(chkMonth>chkConditionMonth){
		// vo.setReservation_dt(frmDate.format(d1.getTime()));
		// chkConditionMonth = chkMonth;
		// mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		// }

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		reservation_use_month = reservation_use_month - 1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		// int maxMonthNum = Integer.parseInt(
		// frmDate1.format(maxMonthChk.getTime().getTime()));
		// if(chkConditionMonth > maxMonthNum){
		// vo.setReservation_dt(maxMonthNum+"01");
		// chkConditionMonth = maxMonthNum;
		// mav.addObject("msg", (reservation_use_month+1)+"개월 이상은 예약이 불가능합니다.");
		//
		// }

		mav.addObject("reservation_dt", vo.getReservation_dt());

		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");

		// 객실 정보
		List list = service.pere101Q(vo);

		// 요금 정보 및 예약정보
		ModelAndView retMv1 = pere200_3Q(vo, req, res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();

		// 달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek = 0;
		int addDate = 0;

		// 일반달력일때
		int year = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int month = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int date = 1;

		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		// 지금 요일
		int day1_7 = cal.get(Calendar.DAY_OF_WEEK);

		// 지금 몇번째 주
		int nowWeek = cal.get(Calendar.DAY_OF_MONTH);

		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

		// 이번달 몇번째주
		sMonthWeek = cal.get(Calendar.WEEK_OF_MONTH);

		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

		cal.get(Calendar.WEEK_OF_YEAR);

		int LastDate = cal.getActualMaximum(Calendar.DATE);

		addDate = (day1_7 + 6) - 7;

		drawCal.set(year, month, date);
		drawCal.add(Calendar.DATE, -addDate);
		textCal.append("<tr class=\"tt\" align=\"center\">");
		for (int i = 0; i < addDate; i++) {
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
			drawCal.add(Calendar.DATE, 1);
		}

		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for (int i = 1; i < 200; i++) {
			// 초기화
			tdHtml.setLength(0);
			int startDate = addDate + i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if (0 != i && "1".equals(dd)) {
				dd = Integer
						.toString(Integer.parseInt(yyymmdd.substring(4, 6)))
						+ "." + dd;
			}
			String gl_busy_type = "";
			String gl_pm_dc = "";
			String gl_pm_dc_style = "";

			String nowBgColor = "@bgcolor";
			if (Integer.parseInt(frmDate.format(d1.getTime().getTime()))
					- Integer.parseInt(frmDate.format(drawCal.getTime()
							.getTime())) == 0) {
				nowBgColor = "#e3fefe";
			}

			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""
					+ nowBgColor + "\"");
			tdHtml.append("	id=\"day_" + yyymmdd + "\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">" + dd
					+ "</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");

			int reservation_cnt = 0; // 예약수
			String for_busy_type = "";
			for (int j = 0; j < list.size(); j++) {

				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");

				int busy_1_base = (Integer) room.get("busy_1_base");
				int busy_1_fri = (Integer) room.get("busy_1_fri");
				int busy_1_sat = (Integer) room.get("busy_1_sat");

				roomsList.setLength(0);

				for (int k = readFast; k < list2.size(); k++) {
					// k=readFast;
					Map dateList = (Map) list2.get(k);

					String reservation_dt = dateList.get("reservation_dt") == null ? ""
							: (String) dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					int rm_no = (Integer) dateList.get("rm_no") == null ? 0
							: (Integer) dateList.get("rm_no");

					if (Integer.parseInt(yyymmdd) < Integer
							.parseInt(reservation_dt)) {

						readFast = k - list.size();
						if (readFast < 0) {
							readFast = 0;
						}
						break;
					}
					if (reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no) {
						String busy_type = (String) dateList.get("busy_type") == null ? ""
								: (String) dateList.get("busy_type");
						for_busy_type = busy_type;
						String rm_status = (String) dateList.get("rm_status") == null ? ""
								: (String) dateList.get("rm_status");
						String reservation_nm = (String) dateList
								.get("reservation_nm") == null ? ""
								: (String) dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1") == null ? ""
								: (String) dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2") == null ? ""
								: (String) dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3") == null ? ""
								: (String) dateList.get("r_phone3");
						int pm_dc_m = dateList.get("pm_dc_m") == null ? 0
								: (Integer) dateList.get("pm_dc_m");
						int pm_per = dateList.get("pm_per") == null ? 0
								: (Integer) dateList.get("pm_per");

						String pm_pay = dateList.get("pm_pay") == null ? ""
								: String.valueOf(dateList.get("pm_pay"));
						gl_pm_dc_style = "margin-top:-10px;";
						if ("".equals(gl_pm_dc)) {
							// if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
							// if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
							// gl_pm_dc+="<br/>";
							// }
							// }
							gl_pm_dc += "<br/>";
							if (!"".equals(pm_pay)
									&& "Y".equals(pensionInfo.get("pm_dc_yn"))) {
								if (pm_dc_m > 0) {
									gl_pm_dc += "(" + "DC : " + pm_dc_m
											+ "원할인)";
								}
								if (pm_per > 0) {
									gl_pm_dc += "(" + "DC : " + pm_per
											+ "% 할인)";
								}
							}
						}

						if ("0101".equals(busy_type)) {
							gl_busy_type = "비수기 주중";
						} else if ("0102".equals(busy_type)) {
							gl_busy_type = "비수기 금요일";
						} else if ("0103".equals(busy_type)) {
							gl_busy_type = "비수기 토요일";
						} else if ("0104".equals(busy_type)) {
							gl_busy_type = "준수기 주중";
						} else if ("0105".equals(busy_type)) {
							gl_busy_type = "준수기 금요일";
						} else if ("0106".equals(busy_type)) {
							gl_busy_type = "준수기 토요일";
						} else if ("0107".equals(busy_type)) {
							gl_busy_type = "성수기 주중";
						} else if ("0108".equals(busy_type)) {
							gl_busy_type = "성수기 금요일";
						} else if ("0109".equals(busy_type)) {
							gl_busy_type = "성수기 토요일";
						} else if ("0110".equals(busy_type)) {
							gl_busy_type = "휴일";
						} else {

							if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
								gl_busy_type = "비수기 토요일";
								busy_type = "0103";
							} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn) // 금요일 사용 함일경우
							) {// 금요일
								gl_busy_type = "비수기 금요일";
								busy_type = "0102";
							} else {// 평일
								gl_busy_type = "비수기 주중";
								busy_type = "0101";
							}
						}
						if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
							gl_busy_type = "";
						}
						if ("0110".equals(busy_type)) {
							roomsList.append(" ");
							// 휴일일때 객실 초기화
						} else {
							roomsList
									.append("					<span	class=\"divDel\"><br/>");
							if ("Y".equals(p_ico_yn)) {
								if ("F".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								} else if ("C".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								} else if ("B".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}
							}
							String viewNm = room_nm;
							if ("C".equals(rm_status)) {
								viewNm = "<span class=\"ptrend\">완료["
										+ reservation_nm + "]</span>";
								reservation_cnt++;
							} else if ("R".equals(rm_status)) {
								viewNm = "<span class=\"ptrstandby\">대기["
										+ reservation_nm + "]</span>";
								reservation_cnt++;
							}
							String r_phone = "";
							if (null != r_phone1 && !"".equals(r_phone1)) {
								r_phone = r_phone1 + "-" + r_phone2 + "-"
										+ r_phone3;
							}

							roomsList
									.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
							roomsList
									.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
							roomsList
									.append("							onmouseout=\"hideTip()\"> ");
							roomsList.append("							<a href=\"#\" id=\"a_"
									+ pr_no + "_" + yyymmdd + "\"");
							roomsList
									.append("								onclick=\"goReserrvation('"
											+ p_id
											+ "',this,'"
											+ pr_no
											+ "');\" room_nm=\" "
											+ room_nm
											+ "\"");
							roomsList.append("								room_form=\"" + room_form
									+ "\" room_type=\"" + room_type
									+ "\" rm_status=\"" + rm_status
									+ "\" date=\"" + yyymmdd + "\"");
							roomsList.append("								busy_1_base=\""
									+ busy_1_base + "\" busy_1_fri=\""
									+ busy_1_fri + "\" busy_1_sat=\""
									+ busy_1_sat + "\" ");
							if (!"".equals(reservation_nm)) {
								roomsList.append("								reservation_nm=\""
										+ reservation_nm + "\" r_phone=\""
										+ r_phone + "\" ");
							}

							if (!"".equals(pm_pay)) {
								roomsList.append("						pm_pay=\"" + pm_pay
										+ "\"");
							}
							if (0 != rm_no) {
								roomsList.append("						rm_no=\"" + rm_no
										+ "\"");
							}

							roomsList.append("								busy_type=\"" + busy_type
									+ "\"> " + viewNm + "</a>");
							roomsList.append("						</span>");
							roomsList.append("					</span>");
						}

					}
				}
				// 설정 안되어있을경우 기본으로 설정합
				if ("".equals(roomsList.toString())) {
					// 요금 설정해야함.
					String busy_type = "";

					if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
						gl_busy_type = "비수기 토요일";
						busy_type = "0103";
					} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn) // 금요일 사용 함일경우
					) {// 금요일
						gl_busy_type = "비수기 금요일";
						busy_type = "0102";
					} else {// 평일
						gl_busy_type = "비수기 주중";
						busy_type = "0101";
					}
					if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
						gl_busy_type = "";
					}

					// 기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if ("Y".equals(p_ico_yn)) {
						if ("F".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("C".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("B".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList
							.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList
							.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_" + pr_no
							+ "_" + yyymmdd + "\"");
					roomsList.append("								onclick=\"goReserrvation('"
							+ p_id + "',this,'" + pr_no + "');\" room_nm=\" "
							+ room_nm + "\"");
					roomsList.append("								room_form=\"" + room_form
							+ "\" room_type=\"" + room_type
							+ "\" rm_status=\"\" date=\"" + yyymmdd + "\"");
					roomsList.append("								busy_1_base=\"" + busy_1_base
							+ "\" busy_1_fri=\"" + busy_1_fri
							+ "\" busy_1_sat=\"" + busy_1_sat + "\" ");
					roomsList.append("								busy_type=\"" + busy_type
							+ "\"> " + room_nm + "</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				} else {

				}
				// 휴일일 경우 객실정보 입력안함
				if (!"0110".equals(for_busy_type)) {
					tdHtml.append(roomsList.toString());
				}
			}
			// 휴일일경우 이미지로 대체
			if ("0110".equals(for_busy_type)) {
				tdHtml.append("<br/><table style=\"width:100%;height:100%;text-align: center\"><tr><td valign='middle'><img src=\"/usr/images/reservation.jpg\" border=\"0\" style=\"\"/></td></tr></table>");
			}
			// ///

			// 색지정
			if (reservation_cnt == 0) {// 예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));

			} else if (reservation_cnt == list.size()) {// 예약 모두 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			} else {// 예약 조금 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");

			if (startDate % 7 == 0) {
				textCal.append("</tr>");
				if (sMonthWeek == chkWeek) {
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);

		}

		mav.addObject("txtCal", textCal.toString());

		mav.addObject("pensionInfo", pensionInfo);

		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}

	/**
	 * 1200 테스트 완료 되면 삭제
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1300Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));

		// 이전달 조회 금지
		if (chkMonth > chkConditionMonth) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		reservation_use_month = reservation_use_month - 1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt(frmDate1.format(maxMonthChk
				.getTime().getTime()));
		if (chkConditionMonth > maxMonthNum) {
			vo.setReservation_dt(maxMonthNum + "01");
			chkConditionMonth = maxMonthNum;
			mav.addObject("msg", (reservation_use_month + 1)
					+ "개월 이상은 예약이 불가능합니다.");

		}

		mav.addObject("reservation_dt", vo.getReservation_dt());

		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");

		// 객실 정보
		List list = service.pere101Q(vo);

		// 요금 정보 및 예약정보
		ModelAndView retMv1 = pere200_3Q(vo, req, res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();

		// 달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek = 0;
		int addDate = 0;

		// 일반달력일때
		int year = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int month = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int date = 1;

		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		// 지금 요일
		int day1_7 = cal.get(Calendar.DAY_OF_WEEK);

		// 지금 몇번째 주
		int nowWeek = cal.get(Calendar.DAY_OF_MONTH);

		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

		// 이번달 몇번째주
		sMonthWeek = cal.get(Calendar.WEEK_OF_MONTH);

		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

		cal.get(Calendar.WEEK_OF_YEAR);

		int LastDate = cal.getActualMaximum(Calendar.DATE);

		addDate = (day1_7 + 6) - 7;

		drawCal.set(year, month, date);
		drawCal.add(Calendar.DATE, -addDate);
		textCal.append("<tr class=\"tt\" align=\"center\">");
		for (int i = 0; i < addDate; i++) {
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
			drawCal.add(Calendar.DATE, 1);
		}

		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for (int i = 1; i < 200; i++) {
			// 초기화
			tdHtml.setLength(0);
			int startDate = addDate + i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if (0 != i && "1".equals(dd)) {
				dd = Integer
						.toString(Integer.parseInt(yyymmdd.substring(4, 6)))
						+ "." + dd;
			}
			String gl_busy_type = "";
			String gl_pm_dc = "";
			String gl_pm_dc_style = "";

			String nowBgColor = "@bgcolor";
			if (Integer.parseInt(frmDate.format(d1.getTime().getTime()))
					- Integer.parseInt(frmDate.format(drawCal.getTime()
							.getTime())) == 0) {
				nowBgColor = "#e3fefe";
			}

			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""
					+ nowBgColor + "\"");
			tdHtml.append("	id=\"day_" + yyymmdd + "\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">" + dd
					+ "</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");

			int reservation_cnt = 0; // 예약수
			for (int j = 0; j < list.size(); j++) {

				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");

				int busy_1_base = (Integer) room.get("busy_1_base");
				int busy_1_fri = (Integer) room.get("busy_1_fri");
				int busy_1_sat = (Integer) room.get("busy_1_sat");

				roomsList.setLength(0);

				for (int k = readFast; k < list2.size(); k++) {
					// k=readFast;
					Map dateList = (Map) list2.get(k);

					String reservation_dt = dateList.get("reservation_dt") == null ? ""
							: (String) dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					int rm_no = (Integer) dateList.get("rm_no") == null ? 0
							: (Integer) dateList.get("rm_no");

					if (Integer.parseInt(yyymmdd) < Integer
							.parseInt(reservation_dt)) {

						readFast = k - list.size();
						if (readFast < 0) {
							readFast = 0;
						}
						break;
					}
					if (reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no) {
						String busy_type = (String) dateList.get("busy_type") == null ? ""
								: (String) dateList.get("busy_type");
						String rm_status = (String) dateList.get("rm_status") == null ? ""
								: (String) dateList.get("rm_status");
						String reservation_nm = (String) dateList
								.get("reservation_nm") == null ? ""
								: (String) dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1") == null ? ""
								: (String) dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2") == null ? ""
								: (String) dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3") == null ? ""
								: (String) dateList.get("r_phone3");
						int pm_dc_m = dateList.get("pm_dc_m") == null ? 0
								: (Integer) dateList.get("pm_dc_m");
						int pm_per = dateList.get("pm_per") == null ? 0
								: (Integer) dateList.get("pm_per");

						String pm_pay = dateList.get("pm_pay") == null ? ""
								: String.valueOf(dateList.get("pm_pay"));
						gl_pm_dc_style = "margin-top:-10px;";
						if ("".equals(gl_pm_dc)) {
							// if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
							// if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
							// gl_pm_dc+="<br/>";
							// }
							// }
							gl_pm_dc += "<br/>";
							if (!"".equals(pm_pay)
									&& "Y".equals(pensionInfo.get("pm_dc_yn"))) {
								if (pm_dc_m > 0) {
									gl_pm_dc += "(" + "DC : " + pm_dc_m
											+ "원할인)";
								}
								if (pm_per > 0) {
									gl_pm_dc += "(" + "DC : " + pm_per
											+ "% 할인)";
								}
							}
						}

						if ("0101".equals(busy_type)) {
							gl_busy_type = "비수기 주중";
						} else if ("0102".equals(busy_type)) {
							gl_busy_type = "비수기 금요일";
						} else if ("0103".equals(busy_type)) {
							gl_busy_type = "비수기 토요일";
						} else if ("0104".equals(busy_type)) {
							gl_busy_type = "준수기 주중";
						} else if ("0105".equals(busy_type)) {
							gl_busy_type = "준수기 금요일";
						} else if ("0106".equals(busy_type)) {
							gl_busy_type = "준수기 토요일";
						} else if ("0107".equals(busy_type)) {
							gl_busy_type = "성수기 주중";
						} else if ("0108".equals(busy_type)) {
							gl_busy_type = "성수기 금요일";
						} else if ("0109".equals(busy_type)) {
							gl_busy_type = "성수기 토요일";
						} else {

							if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
								gl_busy_type = "비수기 토요일";
								busy_type = "0103";
							} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn) // 금요일 사용 함일경우
							) {// 금요일
								gl_busy_type = "비수기 금요일";
								busy_type = "0102";
							} else {// 평일
								gl_busy_type = "비수기 주중";
								busy_type = "0101";
							}
						}
						if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
							gl_busy_type = "";
						}

						roomsList.append("					<span	class=\"divDel\"><br/>");
						if ("Y".equals(p_ico_yn)) {
							if ("F".equals(room_type)) {
								roomsList
										.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
							} else if ("C".equals(room_type)) {
								roomsList
										.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
							} else if ("B".equals(room_type)) {
								roomsList
										.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
							}
						}
						String viewNm = room_nm;
						if ("C".equals(rm_status)) {
							viewNm = "<span class=\"ptrend\">완료["
									+ reservation_nm + "]</span>";
							reservation_cnt++;
						} else if ("R".equals(rm_status)) {
							viewNm = "<span class=\"ptrstandby\">대기["
									+ reservation_nm + "]</span>";
							reservation_cnt++;
						}
						String r_phone = "";
						if (null != r_phone1 && !"".equals(r_phone1)) {
							r_phone = r_phone1 + "-" + r_phone2 + "-"
									+ r_phone3;
						}

						roomsList
								.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
						roomsList
								.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
						roomsList.append("							onmouseout=\"hideTip()\"> ");
						roomsList.append("							<a href=\"#\" id=\"a_" + pr_no
								+ "_" + yyymmdd + "\"");
						roomsList.append("								onclick=\"goReserrvation('"
								+ p_id + "',this,'" + pr_no
								+ "');\" room_nm=\" " + room_nm + "\"");
						roomsList.append("								room_form=\"" + room_form
								+ "\" room_type=\"" + room_type
								+ "\" rm_status=\"" + rm_status + "\" date=\""
								+ yyymmdd + "\"");
						roomsList.append("								busy_1_base=\"" + busy_1_base
								+ "\" busy_1_fri=\"" + busy_1_fri
								+ "\" busy_1_sat=\"" + busy_1_sat + "\" ");
						if (!"".equals(reservation_nm)) {
							roomsList.append("								reservation_nm=\""
									+ reservation_nm + "\" r_phone=\""
									+ r_phone + "\" ");
						}

						if (!"".equals(pm_pay)) {
							roomsList.append("						pm_pay=\"" + pm_pay + "\"");
						}
						if (0 != rm_no) {
							roomsList.append("						rm_no=\"" + rm_no + "\"");
						}

						roomsList.append("								busy_type=\"" + busy_type
								+ "\"> " + viewNm + "</a>");
						roomsList.append("						</span>");
						roomsList.append("					</span>");
					}
				}
				// 설정 안되어있을경우 기본으로 설정합
				if ("".equals(roomsList.toString())) {
					// 요금 설정해야함.
					String busy_type = "";

					if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
						gl_busy_type = "비수기 토요일";
						busy_type = "0103";
					} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn) // 금요일 사용 함일경우
					) {// 금요일
						gl_busy_type = "비수기 금요일";
						busy_type = "0102";
					} else {// 평일
						gl_busy_type = "비수기 주중";
						busy_type = "0101";
					}
					if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
						gl_busy_type = "";
					}

					// 기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if ("Y".equals(p_ico_yn)) {
						if ("F".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("C".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("B".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList
							.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList
							.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_" + pr_no
							+ "_" + yyymmdd + "\"");
					roomsList.append("								onclick=\"goReserrvation('"
							+ p_id + "',this,'" + pr_no + "');\" room_nm=\" "
							+ room_nm + "\"");
					roomsList.append("								room_form=\"" + room_form
							+ "\" room_type=\"" + room_type
							+ "\" rm_status=\"\" date=\"" + yyymmdd + "\"");
					roomsList.append("								busy_1_base=\"" + busy_1_base
							+ "\" busy_1_fri=\"" + busy_1_fri
							+ "\" busy_1_sat=\"" + busy_1_sat + "\" ");
					roomsList.append("								busy_type=\"" + busy_type
							+ "\"> " + room_nm + "</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				} else {

				}
				tdHtml.append(roomsList.toString());
			}

			// 색지정
			if (reservation_cnt == 0) {// 예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));

			} else if (reservation_cnt == list.size()) {// 예약 모두 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			} else {// 예약 조금 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");

			if (startDate % 7 == 0) {
				textCal.append("</tr>");
				if (sMonthWeek == chkWeek) {
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);

		}

		mav.addObject("txtCal", textCal.toString());

		mav.addObject("pensionInfo", pensionInfo);

		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}

	/**
	 * 예약 대기 ,예약 완료 복구
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1400T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView("/common/close");

		List rList = service.pere707_1Q(vo);
		mav.addObject("list", rList);
		List svsList = service.pere707_2Q(vo);

		Map reservationInfo = service.pere705_2Q(vo);
		// 예약자 정보
		// mav.addObject("reservationInfo", reservationInfo);

		PEREVo usrInfo = new PEREVo();
		Map data = new HashMap();
		data.put("list", rList);
		data.put("rtAddSvcList", svsList);
		data.put("reservationInfo", reservationInfo);

		SMCommonUtil smUtil = new SMCommonUtil();
		smUtil.mapToBean(reservationInfo, vo);

		data.put("paramMap", vo);

		SimpleDateFormat frmDatedd = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		int nowDt = Integer.parseInt(frmDatedd.format(d1.getTime().getTime()));
		boolean recovery = false;

		// 예약복구 처리 쿼리
		if (rList != null && 0 < rList.size()) {
			for (int i = 0; i < rList.size(); i++) {
				Map dt = (Map) rList.get(i);
				int chkDate = Integer.parseInt((String) dt
						.get("reservation_dt"));
				if (nowDt <= chkDate) {
					recovery = true;
				} else {
					recovery = false;
					break;
				}
			}
			// 예약이 되어있는지 확인
			if (recovery) {
				vo.setNext_dates(rList);
				int cnt = service.pere707Q(vo);
				if (cnt > 0) {
					recovery = false;
				}
			}

			if (recovery) {

				service.pere1400T(data);

				String reservation_dt = (String) ((Map) rList.get(0))
						.get("reservation_dt");
				mav.setViewName("/common/close");
				mav.addObject("redirect", "./pere1200Q.do?p_id=" + vo.getP_id()
						+ "&reservation_dt=" + reservation_dt);
				mav.addObject("msg", "예약되었습니다");
			} else {
				mav.setViewName("/common/close");
				mav.addObject("redirect", "./pere703Q.do?p_id=" + vo.getP_id());
				mav.addObject("msg",
						"!!!!!!!!!!!!!예약 실패!!!!!!!!!!!!!!! 해당일에 예약이 되어있습니다");
			}
		}

		return mav;
	}

	/**
	 * 문자보내기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1500Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		Map pensionInfo = petiService.peti300Q(petiVo);
		mav.addObject("pensionInfo", pensionInfo);
		List list = service.pere1500Q(vo);
		List returnList = new ArrayList();
		if (list != null && list.size() > 0) {
			String reservation_dt = "";
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				if (!map.get("reservation_dt").equals(reservation_dt)) {
					map.put("col", map.get("row_cnt"));
					reservation_dt = (String) map.get("reservation_dt");
				}
				returnList.add(map);
			}
		}
		mav.addObject("smsReservationList", returnList);

		return mav;
	}

	/**
	 * sms문자전송 전송내용
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1501Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		if (null != vo.getSrc_sdate() && !"".equals(vo.getSrc_sdate())) {
			vo.setSrc_sdate(vo.getSrc_sdate().replaceAll("-", "") + "%");
		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		mav.addObject("pensionInfo", pensionInfo);
		// mav.addObject("smsList", pensionInfo);
		vo.setRecordCountPerPage(10);
		PaginationInfo paginationInfo = new PaginationInfo();
		int currnetPageNo = vo.getCurrentPageNo() <= 1 ? 1 : (Integer) vo
				.getCurrentPageNo();
		vo.setCurrentPageNo(currnetPageNo);
		vo.setParamMap(requestPram2Map(req));

		int iTotalCnt = service.pere1501Q_cnt(vo);
		vo.setTotalRecordCount(iTotalCnt);

		if (iTotalCnt > 0) {

			// 상위 코드목록
			mav.addObject("list", service.pere1501Q(vo));
			mav.addObject("pageHtml", vo.getToHtml("./pere1501Q.do"));
			mav.addObject("paginationInfo", vo);
		}

		List list = service.pere1500Q(vo);
		List returnList = new ArrayList();
		if (list != null && list.size() > 0) {
			String reservation_dt = "";
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				if (!map.get("reservation_dt").equals(reservation_dt)) {
					map.put("col", map.get("row_cnt"));
					reservation_dt = (String) map.get("reservation_dt");
				}
				returnList.add(map);
			}
		}
		mav.addObject("smsReservationList", returnList);

		return mav;
	}

	/**
	 * sms 삭제
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1502T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView();
		mav.setViewName("/common/close");
		mav.addObject("redirect", "./pere1501Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "삭제했습니다");
		String[] etc_data = vo.getEtc_data().split(";");
		List list = new ArrayList();

		for (int i = 0; i < etc_data.length; i++) {
			list.add(etc_data[i]);
		}
		vo.setList(list);

		service.pere1502T(vo);
		return mav;
	}

	/**
	 * 문자 전송 프로세스
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1600T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView();
		SMSUtil smsUtil = new SMSUtil();

		String send = vo.getSendPhone();
		String msg = vo.getReq_msg();

		StringBuffer ReturnMsg = new StringBuffer();

		for (int i = 0; i < vo.getPhones().length; i++) {
			String recive = vo.getPhones()[i];
			String returnCode = "";
			
			PETIVo petiVo = new PETIVo();
			petiVo.setP_id(vo.getP_id());
			Map pensionInfo = petiService.peti300Q(petiVo);
			if("Y".equals(pensionInfo.get("sms_send_yn"))){
				int chk_sms_cnt = Integer.parseInt( pensionInfo.get("sms_cnt").toString());
				
				if(chk_sms_cnt > 0){

					
					if ("1".equals(vo.getSendType())) {
						// 바로 전송
						returnCode = smsUtil.send(send, recive,
								JspUtil.getByteSizeToString(msg.toString(), 80));

					} else {
						// 예약전송
						String res_dt = vo.getRes_dt();
						String res_tm = vo.getRes_tm();
						SimpleDateFormat frmDate1 = new SimpleDateFormat(
								"yyyyMMddHHmmss");
						Calendar d1 = Calendar.getInstance();
						String seq = frmDate1.format(d1.getTime()) + i;
						returnCode = smsUtil.sendSMSReserve(send, recive,
								JspUtil.getByteSizeToString(msg.toString(), 80),
								res_dt, res_tm, seq);

						vo.setSms_reservation_no(seq);
						vo.setReservation_dt(res_dt.replaceAll("-", "")
								+ res_tm.replaceAll(":", ""));
					}

					vo.setFrom_no(send);
					vo.setTo_no(recive);
					vo.setSms_content(JspUtil.getByteSizeToString(msg.toString(), 80));
					vo.setC_code(returnCode);
					vo.setC_msg(smsUtil.smsReturnMsg(vo.getC_code()));

					service.pere710Q(vo);
					if ("1".equals(returnCode)) {
						// sms 카운트 줄이기
						service.pere711Q(vo);
						ReturnMsg.append(recive);
						ReturnMsg.append(" : 전송 성공&nn");

					} else {
						ReturnMsg.append(recive);
						ReturnMsg.append(" : 전송 실패(");
						ReturnMsg.append(vo.getC_msg());
						ReturnMsg.append(")&nn");
					}		
				}
			}
		}
		mav.setViewName("/common/close");
		mav.addObject("redirect", "./pere1500Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", ReturnMsg.toString());

		return mav;
	}

	/**
	 * sms 예약전송 취소
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1601T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView();
		SMSUtil smsUtil = new SMSUtil();

		String send = vo.getSendPhone();
		String msg = vo.getReq_msg();

		StringBuffer ReturnMsg = new StringBuffer();

		for (int i = 0; i < vo.getSms_reservation_nos().length; i++) {

			vo.setSms_reservation_no(vo.getSms_reservation_nos()[i]);
			// 예약취소
			int returnInt = smsUtil.cancelSMSReserve(vo
					.getSms_reservation_nos()[i]);
			// 예약전송

			if (returnInt == 1) {
				// sms 카운트 +1
				service.pere710_0Q(vo);
				service.pere712Q(vo);
				// ReturnMsg.append(recive);
				// ReturnMsg.append(" : 전송 성공&nn");

			} else {
				// ReturnMsg.append(recive);
				// ReturnMsg.append(" : 전송 실패(");
				// ReturnMsg.append(vo.getC_msg());
				// ReturnMsg.append(")&nn");
			}
		}
		mav.setViewName("/common/close");
		mav.addObject("redirect", "./pere1500Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "예약전송 삭제 되었습니다");

		return mav;
	}

	/**
	 * 게시판별 문자 불러오기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1700Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();

		jsonMap.put("list", service.pere1700Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * sms 문자 저장하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1800T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		service.pere1800T(vo);

		jsonMap.put("resultCode", "Y");
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * sms 문자 삭제하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere1900T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();

		jsonMap.put("resultCode", service.pere1900T(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 해당 구간 사용자 전화번호 이름 조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2000Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}

		vo.setSrc_sdt(vo.getSrc_sdt().replaceAll("-", ""));
		vo.setSrc_edt(vo.getSrc_edt().replaceAll("-", ""));

		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();

		jsonMap.put("list", service.pere2000Q(vo));
		mav.addObject("map", jsonMap);
		return mav;
	}

	/**
	 * 게시판 조회
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2100Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("list", service.pere2100Q(vo));
		return mav;
	}

	/**
	 * 휴대전화로 인증처리
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2200Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		mav.addObject("list", service.pere2200Q(vo));
		return mav;
	}

	/**
	 * 예약현황조회 팝업
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView perePop1200Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));

		// 이전달 조회 금지
		// if(chkMonth>chkConditionMonth){
		// vo.setReservation_dt(frmDate.format(d1.getTime()));
		// chkConditionMonth = chkMonth;
		// mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		// }

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		reservation_use_month = reservation_use_month - 1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		// int maxMonthNum = Integer.parseInt(
		// frmDate1.format(maxMonthChk.getTime().getTime()));
		// if(chkConditionMonth > maxMonthNum){
		// vo.setReservation_dt(maxMonthNum+"01");
		// chkConditionMonth = maxMonthNum;
		// mav.addObject("msg", (reservation_use_month+1)+"개월 이상은 예약이 불가능합니다.");
		//
		// }

		mav.addObject("reservation_dt", vo.getReservation_dt());

		SimpleDateFormat frmDateDD = new SimpleDateFormat("d");

		// 객실 정보
		List list = service.pere101Q(vo);

		// 요금 정보 및 예약정보
		ModelAndView retMv1 = pere200_3Q(vo, req, res);
		List list2 = (List) ((Map) retMv1.getModel().get("map")).get("list");

		StringBuffer textCal = new StringBuffer();

		// 달력 설정하는 부분
		Calendar drawCal = Calendar.getInstance();
		int sMonthWeek = 0;
		int addDate = 0;

		// 일반달력일때
		int year = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
		int month = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
		int date = 1;

		Calendar cal = Calendar.getInstance();
		cal.set(year, month, date);
		// 지금 요일
		int day1_7 = cal.get(Calendar.DAY_OF_WEEK);

		// 지금 몇번째 주
		int nowWeek = cal.get(Calendar.DAY_OF_MONTH);

		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

		// 이번달 몇번째주
		sMonthWeek = cal.get(Calendar.WEEK_OF_MONTH);

		cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));

		cal.get(Calendar.WEEK_OF_YEAR);

		int LastDate = cal.getActualMaximum(Calendar.DATE);

		addDate = (day1_7 + 6) - 7;

		drawCal.set(year, month, date);
		drawCal.add(Calendar.DATE, -addDate);
		textCal.append("<tr class=\"tt\" align=\"center\">");
		for (int i = 0; i < addDate; i++) {
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
			drawCal.add(Calendar.DATE, 1);
		}

		int chkWeek = 1;
		StringBuffer roomsList = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();
		int readFast = 0;
		for (int i = 1; i < 200; i++) {
			// 초기화
			tdHtml.setLength(0);
			int startDate = addDate + i;
			String yyymmdd = frmDate.format(drawCal.getTime().getTime());
			String dd = frmDateDD.format(drawCal.getTime().getTime());
			if (0 != i && "1".equals(dd)) {
				dd = Integer
						.toString(Integer.parseInt(yyymmdd.substring(4, 6)))
						+ "." + dd;
			}
			String gl_busy_type = "";
			String gl_pm_dc = "";
			String gl_pm_dc_style = "";

			String nowBgColor = "@bgcolor";
			if (Integer.parseInt(frmDate.format(d1.getTime().getTime()))
					- Integer.parseInt(frmDate.format(drawCal.getTime()
							.getTime())) == 0) {
				nowBgColor = "#e3fefe";
			}

			tdHtml.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\""
					+ nowBgColor + "\"");
			tdHtml.append("	id=\"day_" + yyymmdd + "\">");
			tdHtml.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
			tdHtml.append("		<tbody>");
			tdHtml.append("			<tr>");
			tdHtml.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
			tdHtml.append("					<font color=\"green\">" + dd
					+ "</font></a></b>");
			tdHtml.append("					<span class=\"pm_nm pms\">@pm_nm&nbsp;</span>");
			tdHtml.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;@pm_dc_style\">@pm_dc1&nbsp;</span>");

			int reservation_cnt = 0; // 예약수
			String for_busy_type = "";
			for (int j = 0; j < list.size(); j++) {

				Map room = (Map) list.get(j);
				int pr_no = (Integer) room.get("pr_no");
				String room_nm = (String) room.get("room_nm");
				String room_type = (String) room.get("room_type");
				String room_form = (String) room.get("room_form");

				int busy_1_base = (Integer) room.get("busy_1_base");
				int busy_1_fri = (Integer) room.get("busy_1_fri");
				int busy_1_sat = (Integer) room.get("busy_1_sat");

				roomsList.setLength(0);

				for (int k = readFast; k < list2.size(); k++) {
					// k=readFast;
					Map dateList = (Map) list2.get(k);

					String reservation_dt = dateList.get("reservation_dt") == null ? ""
							: (String) dateList.get("reservation_dt");
					int rd_pr_no = (Integer) dateList.get("pr_no");
					int rm_no = (Integer) dateList.get("rm_no") == null ? 0
							: (Integer) dateList.get("rm_no");

					if (Integer.parseInt(yyymmdd) < Integer
							.parseInt(reservation_dt)) {

						readFast = k - list.size();
						if (readFast < 0) {
							readFast = 0;
						}
						break;
					}
					if (reservation_dt.equals(yyymmdd) && pr_no == rd_pr_no) {
						String busy_type = (String) dateList.get("busy_type") == null ? ""
								: (String) dateList.get("busy_type");
						for_busy_type = busy_type;
						String rm_status = (String) dateList.get("rm_status") == null ? ""
								: (String) dateList.get("rm_status");
						String reservation_nm = (String) dateList
								.get("reservation_nm") == null ? ""
								: (String) dateList.get("reservation_nm");
						String r_phone1 = (String) dateList.get("r_phone1") == null ? ""
								: (String) dateList.get("r_phone1");
						String r_phone2 = (String) dateList.get("r_phone2") == null ? ""
								: (String) dateList.get("r_phone2");
						String r_phone3 = (String) dateList.get("r_phone3") == null ? ""
								: (String) dateList.get("r_phone3");
						int pm_dc_m = dateList.get("pm_dc_m") == null ? 0
								: (Integer) dateList.get("pm_dc_m");
						int pm_per = dateList.get("pm_per") == null ? 0
								: (Integer) dateList.get("pm_per");

						String pm_pay = dateList.get("pm_pay") == null ? ""
								: String.valueOf(dateList.get("pm_pay"));
						gl_pm_dc_style = "margin-top:-10px;";
						if ("".equals(gl_pm_dc)) {
							// if("Y".equals(pensionInfo.get("pm_dc_yn")) ){
							// if("Y".equals(pensionInfo.get("pm_nm_yn")) ){
							// gl_pm_dc+="<br/>";
							// }
							// }
							gl_pm_dc += "<br/>";
							if (!"".equals(pm_pay)
									&& "Y".equals(pensionInfo.get("pm_dc_yn"))) {
								if (pm_dc_m > 0) {
									gl_pm_dc += "(" + "DC : " + pm_dc_m
											+ "원할인)";
								}
								if (pm_per > 0) {
									gl_pm_dc += "(" + "DC : " + pm_per
											+ "% 할인)";
								}
							}
						}

						if ("0101".equals(busy_type)) {
							gl_busy_type = "비수기 주중";
						} else if ("0102".equals(busy_type)) {
							gl_busy_type = "비수기 금요일";
						} else if ("0103".equals(busy_type)) {
							gl_busy_type = "비수기 토요일";
						} else if ("0104".equals(busy_type)) {
							gl_busy_type = "준수기 주중";
						} else if ("0105".equals(busy_type)) {
							gl_busy_type = "준수기 금요일";
						} else if ("0106".equals(busy_type)) {
							gl_busy_type = "준수기 토요일";
						} else if ("0107".equals(busy_type)) {
							gl_busy_type = "성수기 주중";
						} else if ("0108".equals(busy_type)) {
							gl_busy_type = "성수기 금요일";
						} else if ("0109".equals(busy_type)) {
							gl_busy_type = "성수기 토요일";
						} else if ("0110".equals(busy_type)) {
							gl_busy_type = "휴일";
						} else {

							if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
								gl_busy_type = "비수기 토요일";
								busy_type = "0103";
							} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
									&& "Y".equals(friday_yn) // 금요일 사용 함일경우
							) {// 금요일
								gl_busy_type = "비수기 금요일";
								busy_type = "0102";
							} else {// 평일
								gl_busy_type = "비수기 주중";
								busy_type = "0101";
							}
						}
						if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
							gl_busy_type = "";
						}
						if ("0110".equals(busy_type)) {
							roomsList.append(" ");
							// 휴일일때 객실 초기화
						} else {
							roomsList
									.append("					<span	class=\"divDel\"><br/>");
							if ("Y".equals(p_ico_yn)) {
								if ("F".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								} else if ("C".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								} else if ("B".equals(room_type)) {
									roomsList
											.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
								}
							}
							String viewNm = room_nm;
							if ("C".equals(rm_status)) {
								viewNm = "<span class=\"ptrend\">완료["
										+ reservation_nm + "]</span>";
								reservation_cnt++;
							} else if ("R".equals(rm_status)) {
								viewNm = "<span class=\"ptrstandby\">대기["
										+ reservation_nm + "]</span>";
								reservation_cnt++;
							}
							String r_phone = "";
							if (null != r_phone1 && !"".equals(r_phone1)) {
								r_phone = r_phone1 + "-" + r_phone2 + "-"
										+ r_phone3;
							}

							roomsList
									.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
							roomsList
									.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
							roomsList
									.append("							onmouseout=\"hideTip()\"> ");
							roomsList.append("							<a href=\"#\" id=\"a_"
									+ pr_no + "_" + yyymmdd + "\"");
							roomsList
									.append("								onclick=\"goReserrvation('"
											+ p_id
											+ "',this,'"
											+ pr_no
											+ "');\" room_nm=\" "
											+ room_nm
											+ "\"");
							roomsList.append("								room_form=\"" + room_form
									+ "\" room_type=\"" + room_type
									+ "\" rm_status=\"" + rm_status
									+ "\" date=\"" + yyymmdd + "\"");
							roomsList.append("								busy_1_base=\""
									+ busy_1_base + "\" busy_1_fri=\""
									+ busy_1_fri + "\" busy_1_sat=\""
									+ busy_1_sat + "\" ");
							if (!"".equals(reservation_nm)) {
								roomsList.append("								reservation_nm=\""
										+ reservation_nm + "\" r_phone=\""
										+ r_phone + "\" ");
							}

							if (!"".equals(pm_pay)) {
								roomsList.append("						pm_pay=\"" + pm_pay
										+ "\"");
							}
							if (0 != rm_no) {
								roomsList.append("						rm_no=\"" + rm_no
										+ "\"");
							}

							roomsList.append("								busy_type=\"" + busy_type
									+ "\"> " + viewNm + "</a>");
							roomsList.append("						</span>");
							roomsList.append("					</span>");
						}

					}
				}
				// 설정 안되어있을경우 기본으로 설정합
				if ("".equals(roomsList.toString())) {
					// 요금 설정해야함.
					String busy_type = "";

					if (7 == drawCal.get(Calendar.DAY_OF_WEEK)) {// 토요일
						gl_busy_type = "비수기 토요일";
						busy_type = "0103";
					} else if (6 == drawCal.get(Calendar.DAY_OF_WEEK)
							&& "Y".equals(friday_yn) // 금요일 사용 함일경우
					) {// 금요일
						gl_busy_type = "비수기 금요일";
						busy_type = "0102";
					} else {// 평일
						gl_busy_type = "비수기 주중";
						busy_type = "0101";
					}
					if ("N".equals(pensionInfo.get("pm_nm_yn"))) {
						gl_busy_type = "";
					}

					// 기본값 설정
					roomsList.append("					<span	class=\"divDel\"><br/>");
					if ("Y".equals(p_ico_yn)) {
						if ("F".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_family.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("C".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_couple.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						} else if ("B".equals(room_type)) {
							roomsList
									.append("						<img src=\"/usr/images/res_icon_big.gif\" width=\"10\" height=\"10\" border=\"0\"/>");
						}
					}
					roomsList
							.append("						<span class=\"ptrnomal\" style=\"cursor: hand\"");
					roomsList
							.append("							onmouseover=\"doTooltip(this);\" onmousemove=\"moveTip(this);\"");
					roomsList.append("							onmouseout=\"hideTip()\"> ");
					roomsList.append("							<a href=\"#\" id=\"a_" + pr_no
							+ "_" + yyymmdd + "\"");
					roomsList.append("								onclick=\"goReserrvation('"
							+ p_id + "',this,'" + pr_no + "');\" room_nm=\" "
							+ room_nm + "\"");
					roomsList.append("								room_form=\"" + room_form
							+ "\" room_type=\"" + room_type
							+ "\" rm_status=\"\" date=\"" + yyymmdd + "\"");
					roomsList.append("								busy_1_base=\"" + busy_1_base
							+ "\" busy_1_fri=\"" + busy_1_fri
							+ "\" busy_1_sat=\"" + busy_1_sat + "\" ");
					roomsList.append("								busy_type=\"" + busy_type
							+ "\"> " + room_nm + "</a>");
					roomsList.append("						</span>");
					roomsList.append("					</span>");
				} else {

				}
				// 휴일일 경우 객실정보 입력안함
				if (!"0110".equals(for_busy_type)) {
					tdHtml.append(roomsList.toString());
				}
			}
			// 휴일일경우 이미지로 대체
			if ("0110".equals(for_busy_type)) {
				tdHtml.append("<br/><table style=\"width:100%;height:100%;text-align: center\"><tr><td valign='middle'><img src=\"/usr/images/reservation.jpg\" border=\"0\" style=\"\"/></td></tr></table>");
			}
			// ///

			// 색지정
			if (reservation_cnt == 0) {// 예약 없을때
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fefefe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));

			} else if (reservation_cnt == list.size()) {// 예약 모두 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fafc98")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			} else {// 예약 조금 찬거
				textCal.append(tdHtml.toString().replace("@bgcolor", "#fef0fe")
						.replace("@pm_nm", gl_busy_type)
						.replace("@pm_dc1", gl_pm_dc)
						.replace("@pm_dc_style", gl_pm_dc_style));
			}

			textCal.append("				</td>");
			textCal.append("			</tr>");
			textCal.append("		</tbody>");
			textCal.append("	</table>");
			textCal.append("</td>");

			if (startDate % 7 == 0) {
				textCal.append("</tr>");
				if (sMonthWeek == chkWeek) {
					break;
				}
				textCal.append("<tr class=\"tt\" align=\"center\">");
				chkWeek++;
			}
			drawCal.add(Calendar.DATE, 1);

		}

		mav.addObject("txtCal", textCal.toString());

		mav.addObject("pensionInfo", pensionInfo);

		vo.setSb_type("brd");
		mav.addObject("brdList", service.pere100Q(vo));
		vo.setSb_type("hot");
		mav.addObject("hotList", service.pere100Q(vo));
		return mav;
	}

	/**
	 * sms 타이틀 수정하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView pere2300T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		isMember(req, res);

		ModelAndView mav = new ModelAndView("common/toJson");
		Map jsonMap = new HashMap();
		jsonMap.put("cnt", service.pere2300T(vo));
		mav.addObject("map", jsonMap);

		return mav;
	}

	/**
	 * 캠핑 메인화면
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc100Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();
		
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));

		// 이전달 조회 금지
		if (chkMonth > chkConditionMonth) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;

			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
			return mav;
		}

		Map pensionInfo = petiService.peti300Q(petiVo);
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		
		reservation_use_month = reservation_use_month;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt(frmDate1.format(maxMonthChk
				.getTime().getTime()));
		if (chkConditionMonth > maxMonthNum) {
			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id()
					+ "&reservation_dt=" + maxMonthNum + "01");
			mav.addObject("msg", (reservation_use_month) + "개월 이상은 예약이 불가능합니다.");
			return mav;
		}

		int group_cnt = Integer.parseInt(pensionInfo.get("group_cnt")
				.toString());
		if (group_cnt < 2) {
			int pg_no = Integer
					.parseInt(pensionInfo.get("group_no").toString());
			mav = new ModelAndView("/common/close");
			// 그룹이 하나일경우 테이블모양으로 보여주기
			// mav.addObject("redirect","./petc0101Q.do?p_id="+vo.getP_id()+"&pg_no="+pg_no);
			mav.addObject("redirect", "./petc1003Q.do?p_id=" + vo.getP_id()
					+ "&pg_no=" + pg_no);
			return mav;
		}

		if ("T".equals(pensionInfo.get("view_type1"))) {
			mav = new ModelAndView("usr/pe/re/petc100_TQ");
		} else {
			// 이미지 기반 달력
			mav = new ModelAndView("usr/pe/re/petc100_IQ");
		}

		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");
		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		mav.addObject("nDtAll", frmDtAll.format(d1.getTime()));

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}

		// 이전달 조회 금지
		// if(chkMonth>chkConditionMonth){
		// vo.setReservation_dt(frmDate.format(d1.getTime()));
		// chkConditionMonth = chkMonth;
		// mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		// }

		Calendar destDate = Calendar.getInstance();

		if (!vo.getReservation_dt().substring(0, 6)
				.equals(frmMonth.format(destDate.getTime()))) {
			destDate.set(
					Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
					Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
					1);
		} else {
			destDate.set(
					Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
					Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
					Integer.parseInt(vo.getReservation_dt().substring(6, 8)));
		}

		Calendar startDate = (Calendar) destDate.clone();
		destDate.set(Calendar.DATE,
				destDate.getActualMaximum(Calendar.DAY_OF_MONTH));
		// 해당월이 몇주가 나오는지
		int week = destDate.get(Calendar.WEEK_OF_MONTH);

		Calendar lastDate = Calendar.getInstance();

		if ("D".equals(pensionInfo.get("reservation_cal"))) {
			// 일반

			// 해당월에 추가되야할 날수
			int addDate = 7 - destDate.get(Calendar.DAY_OF_WEEK);

			destDate.add(Calendar.DATE, addDate);
			lastDate = (Calendar) destDate.clone();
		} else {
			// 이월

			Calendar nowDt = (Calendar) startDate.clone();
			// 해당월에 추가되야할 날수
			int addDate = 7 - startDate.get(Calendar.DAY_OF_WEEK);
			addDate = addDate + (7 * (week - 1));
			nowDt.add(Calendar.DATE, addDate);
			lastDate = (Calendar) nowDt.clone();
		}
		// frmDate.format(startDate.getTime());frmDate.format(lastDate.getTime());
		Calendar addDt = (Calendar) startDate.clone();
		List dateList = new ArrayList();
		long b = (lastDate.getTimeInMillis() - startDate.getTimeInMillis()) / 1000;
		int dateCha = (int) (b / (60 * 60 * 24));
		dateList.add(frmDate.format(addDt.getTime()));
		for (int i = 0; i < dateCha; i++) {
			addDt.add(Calendar.DATE, 1);
			dateList.add(frmDate.format(addDt.getTime()));
		}
		vo.setList(dateList);

		List groupList = service.petc100Q(vo);

		StringBuffer textCal = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();

		int sevenChk = 0;
		if ("T".equals(pensionInfo.get("view_type1"))) {
			// 텍스트 기반
			Calendar stDt = (Calendar) startDate.clone();

			// 빈데이터 처리
			int beforeDt = Integer.parseInt(vo.getReservation_dt().substring(6,
					8));
			if ("D".equals(pensionInfo.get("reservation_cal"))) {
				stDt.set(Calendar.DATE, 1);
				textCal.append("<tr>");
				int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
				for (int i = 0; i < addDate; i++) {
					textCal.append("<td></td>");
					sevenChk++;
				}

				if (!vo.getReservation_dt()
						.substring(0, 6)
						.equals(frmMonth.format(Calendar.getInstance()
								.getTime()))) {
					beforeDt = 0;
				}
				StringBuffer blankRooms = new StringBuffer();
				for (int i = 0; i < group_cnt; i++) {
					blankRooms.append("<li>&nbsp;</li>");
				}
				for (int i = 1; i < beforeDt; i++) {
					sevenChk++;
					textCal.append("<td valign='top'>");

					int dow = stDt.get(Calendar.DAY_OF_WEEK);

					// 일 백그라운드
					String dayBackClass = "calJuganBack";
					String dayFontClass = "";
					// 객실 백그라운드
					String roomBackClass = "";

					if (dow == 7) {// 토요일
						dayBackClass = "calJuganBackSat";
						dayFontClass = "calBlue";
						roomBackClass = "calBackSat";
					} else if (dow == 1) {// 일요일
						dayBackClass = "calJuganBackSun";
						dayFontClass = "calRed";
						roomBackClass = "calBackSun";
					}

					textCal.append("<div class=\"tr ");
					textCal.append(dayBackClass);
					textCal.append("\">");

					if("1".equals(frmd.format(stDt.getTime()))){
						textCal.append("	<strong class=\"" + dayFontClass + "\">"
								+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "</strong>");
					}else{
						textCal.append("	<strong class=\"" + dayFontClass + "\">"
								+ frmd.format(stDt.getTime()) + "</strong>");
					}
//					textCal.append("	<strong class=\"" + dayFontClass + "\">"
//							+ frmd.format(stDt.getTime()) + "</strong>");
					textCal.append("</div>");

					textCal.append("	<div class=\"\">");
					textCal.append("		<ul>");
					textCal.append(blankRooms.toString());
					textCal.append("		</ul>");
					textCal.append("	</div>");

					textCal.append("</td>");

					stDt.add(Calendar.DATE, 1);
					if (sevenChk % 7 == 0) {
						textCal.append("</tr>");
						textCal.append("<tr>");
					}
				}
			} else {
				textCal.append("<tr class=\"tt\" align=\"center\">");
				int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
				for (int i = 0; i < addDate; i++) {
					textCal.append("<td class=\"day2\" bgColor=\"#f8f6f7\" vAlign=\"top\" width=\"14%\">&nbsp;&nbsp;&nbsp;</td>");
					sevenChk++;
				}
			}

			long lDateCha = (lastDate.getTimeInMillis() - startDate
					.getTimeInMillis()) / 1000;
			int forCa = beforeDt + (int) (lDateCha / (60 * 60 * 24));

			int listChk = 0;
			// 데이터 있는 자료 처리
			for (int i = beforeDt; i <= forCa; i++) {
				sevenChk++;
				tdHtml.setLength(0);

				String htmlDt = frmDate.format(stDt.getTime());

				String _busy_type= "";
				for (int j = listChk; j < groupList.size(); j++) {
					Map map = (Map) groupList.get(j);
					listChk = j;
					if (htmlDt.equals(map.get("dt"))) {

						String img = "icon_green.jpg";
						String img_mn = "예약가능";
						int _cnt = Integer.parseInt(map.get("cnt").toString());
						int _group_cnt = Integer.parseInt(map.get("group_cnt")
								.toString());
						if (_cnt == _group_cnt) {
							img = "icon_red.jpg";
							img_mn = "예약블가";
						}
						int relay_day = Integer.parseInt(map.get("relay_day")
								.toString());

						if (relay_day != 0) {
							img_mn += " (부분" + relay_day + "박예약)";
						}
						_busy_type=map.get("busy_type").toString();
						tdHtml.append("<li>");
						tdHtml.append("<a href=\"#\" class=\"divPopup\" onclick=\"goReserrvation('"
								+ map.get("p_id")
								+ "',this,'"
								+ map.get("dt")
								+ "','" + map.get("pg_no") + "');\" ");
						tdHtml.append("dt='" + map.get("dt") + "' busy_type='"
								+ map.get("busy_type") + "' site_nm='"
								+ map.get("group_nm") + "' site=\""
								+ map.get("form") + "\" state2=\"" + img_mn
								+ "\" state1=\"" + _cnt + "/" + _group_cnt
								+ "\">");

						tdHtml.append("<img src=\"/camping/img/" + img
								+ "\" /> ");

						tdHtml.append(map.get("group_nm") + "(" + _cnt + "/"
								+ _group_cnt + ")");
						if (relay_day != 0) {
							tdHtml.append( " (부분" + relay_day + "박예약)");
						}
						tdHtml.append("</a></li>");
						// <p><img src="/camping/img/icon_green.jpg" /> 예약가능,
						// <img src="/camping/img/icon_red.jpg" /> 예약완료</p>
						// ptrend 빨강, ptrnomal 검정, ptrstandby 파랑
					} else {
						break;
					}
				}

				String roomListT = tdHtml.toString();
				if (group_cnt <= 4) {
					roomListT = "<li>&nbsp;</li>" + roomListT
							+ "<li>&nbsp;</li>";
				}
				//
				if (chkConditionMonth == maxMonthNum) {
					if(stDt.getTime().getTime() > maxMonthChk.getTime().getTime()){
						roomListT = "<li>&nbsp;</li>예약불가<li>&nbsp;</li>";
					}
				}
				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "fnt18";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}
				if(dow == 6){
					if("".equals(_busy_type)){_busy_type="0102";}	
				}else if(dow == 7){
					if("".equals(_busy_type)){_busy_type="0103";}
				}else{
					if("".equals(_busy_type)){_busy_type="0101";}
				}
				

				textCal.append("<td valign=\"top\" ");
				textCal.append("	id=\"day_" + htmlDt + "\">");

				textCal.append("<div class=\"");
				textCal.append(dayBackClass);
				textCal.append("\">");
				
				textCal.append("<table width='100%' border=0 cellSpacing=0 cellPadding=0><tr>");
				textCal.append("<td class=\"bold\" style='border:0;width:70%' width='70%'>["+getBusyTypeNm( _busy_type)+"]</td>");
				
				if("1".equals(frmd.format(stDt.getTime()))){

					textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+(stDt.get(Calendar.MONTH)+1)+"."+ frmd.format(stDt.getTime()) + "<strong></td>");
				}else{
					textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+ frmd.format(stDt.getTime()) + "<strong></td>");
				}
				
//				textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+ frmd.format(stDt.getTime()) + "<strong></td>");
				textCal.append("</tr></table>");
//				dayFontClass
//				
//				textCal.append("<div class=\"tl width80\">");
//				textCal.append("	<span style=\"font-size: 11px;\">["+getBusyTypeNm( _busy_type)+"]</span>");
//				textCal.append("</div>");
//				textCal.append("<div class=\"tr width20\">");
//				textCal.append("	<strong class=\"" + dayFontClass + "\">"
//						+ frmd.format(stDt.getTime()) + "</strong>");
				textCal.append("</div>");
//				textCal.append("	<strong class=\"" + dayFontClass + "\"><span style=\"font-size: 11px;\">["+getBusyTypeNm( _busy_type)+"]</span>"
//						+ frmd.format(stDt.getTime()) + "</strong>");
				textCal.append("</div>");

				textCal.append("	<div class=\"" + roomBackClass + "\">");
				textCal.append("		<ul>");
				textCal.append(roomListT);

				textCal.append("		</ul>");
				textCal.append("	</div>");
				textCal.append("</td>");

				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
				
			}
			// 마무리
			textCal.append("</tr>");
		} else {
			// 이미지 기반 달력

			Calendar stDt = (Calendar) startDate.clone();
			// frmDate.format(stDt.getTime());
			// 요일표시부분
			SimpleDateFormat weekday2 = new SimpleDateFormat("EEE",
					java.util.Locale.KOREAN);

			textCal.append("<tr>");
			for (int i = 0; i < dateList.size(); i++) {
				if (i != 0) {
					stDt.add(Calendar.DATE, 1);
				}
				String dayOfTheWeek = weekday2.format(stDt.getTime());
				if ("일".equals(dayOfTheWeek)) {
					textCal.append("<th class=\"calRed\">");
				} else if ("토".equals(dayOfTheWeek)) {
					textCal.append("<th class=\"calBlue\">");
				} else {
					textCal.append("<th class=\"calBlack\">");
				}
				textCal.append(dayOfTheWeek);
				textCal.append("</th>");
			}
			textCal.append("</tr>");
			// frmDate.format(stDt.getTime());
			// 날짜부분 시작
			int listChk = 0;
			stDt = (Calendar) startDate.clone();
			textCal.append("<tr>");
			for (int i = 0; i < dateList.size(); i++) {
				if (i != 0) {
					stDt.add(Calendar.DATE, 1);
				}

				if (stDt.getTimeInMillis() > lastDate.getTimeInMillis()) {
					break;
				}

				Map map = (Map) groupList.get(listChk);

				String dayOfTheWeek = weekday2.format(stDt.getTime());

				if ("일".equals(dayOfTheWeek)) {
					textCal.append("<td class=\"overShow calRed\" ");
				} else if ("토".equals(dayOfTheWeek)) {
					textCal.append("<td class=\"overShow calBlue\" ");
				} else {
					textCal.append("<td class=\"overShow calBlack\" ");
				}

				if (frmDate.format(stDt.getTime()).equals(map.get("dt"))) {
					for (int j = listChk; j < groupList.size(); j++) {
						map = (Map) groupList.get(j);
						listChk = j;
						if (frmDate.format(stDt.getTime())
								.equals(map.get("dt"))) {
							textCal.append(" date=\"");
							textCal.append(frmDate.format(stDt.getTime()));
							textCal.append("\"");
							textCal.append(" cnt");
							textCal.append(map.get("pg_no"));
							textCal.append("=\"");
							textCal.append(map.get("cnt"));
							textCal.append("\"");
							textCal.append(" group_cnt");
							textCal.append(map.get("pg_no"));
							textCal.append("=\"");
							textCal.append(map.get("group_cnt"));
							textCal.append("\"");
						} else {
							break;
						}
					}
				}
				textCal.append(">");
				textCal.append(frmd.format(stDt.getTime()));
				textCal.append("</td>");
			}
			textCal.append("</tr>");

			// 펜션 그룹정보
			mav.addObject("group", petiService.peti501Q(petiVo));
		}

		// 이미지 사이즈 구하기
		String popImg = (String) pensionInfo.get("event_img");
		if (null != popImg && !"".equals(popImg)) {
			String FilePath = req.getSession().getServletContext()
					.getRealPath(popImg);
			File eventImg = new File(FilePath);
			if (eventImg.isFile()) {
				Image img = new ImageIcon(FilePath).getImage();
				mav.addObject("eventW", img.getWidth(null));
				mav.addObject("eventH", img.getHeight(null));
			}
		}

		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("txtCal", textCal.toString());
		mav.addObject("groupList", groupList);
		mav.addObject("reservation_dt", vo.getReservation_dt());
		return mav;
	}

	/**
	 * 펜션 아이디, 그룹 일로 해당 화면 보여주기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0101Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);
		if (!"I".equals(pensionInfo.get("view_type2"))) {
			// 텍스트일경우
			mav = new ModelAndView("usr/pe/re/petc0101_0Q");
		}

		Calendar destDate = Calendar.getInstance();
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");

		if (vo.getReservation_dt() == null) {
			vo.setReservation_dt(frmDate.format(destDate.getTime()));
		}

		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		// 오늘 설정
		mav.addObject("nDtAll", frmDtAll.format(destDate.getTime()));

		destDate.set(Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
				Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
				Integer.parseInt(vo.getReservation_dt().substring(6, 8)));
		// 예약한 날
		mav.addObject("rDtAll", frmDtAll.format(destDate.getTime()));

		Calendar cReservationDt = (Calendar) destDate.clone();

		destDate.add(Calendar.DATE, 7);
		vo.setReservation_next_dt(frmDate.format(destDate.getTime()));

		if ("I".equals(pensionInfo.get("view_type2"))) {
			// 이미지일경우

		} else {
			// 텍스트일경우
			List aList = petiService.peti300_1Q(petiVo);

			List aList1 = new ArrayList();
			List aList2 = new ArrayList();
			List aList3 = new ArrayList();
			List aList4 = new ArrayList();

			if (aList != null && 0 < aList.size()) {
				for (int i = 0; i < aList.size(); i++) {
					Map map = (Map) aList.get(i);
					if ("1".equals(map.get("paa_type"))) {
						// 계좌
						aList1.add(map);
					} else if ("2".equals(map.get("paa_type"))) {
						// 픽업장소
						aList2.add(map);
					} else if ("3".equals(map.get("paa_type"))) {
						// 픽업정보
						aList3.add(map);
					} else if ("4".equals(map.get("paa_type"))) {
						// 도착시간
						aList4.add(map);
					}
				}
			}
			mav.addObject("aList1", aList1);
			mav.addObject("aList2", aList2);
			mav.addObject("aList3", aList3);
			mav.addObject("aList4", aList4);

			// 달력설정
			// Calendar startDt = (Calendar) cReservationDt.clone();
			// startDt.set(Calendar.DATE, 1);

			Calendar startDate = (Calendar) cReservationDt.clone();
			startDate.set(Calendar.DATE, 1);
			// 시작요일확인
			int day1_7 = startDate.get(Calendar.DAY_OF_WEEK);
			StringBuffer calendarHtml = new StringBuffer();
			calendarHtml.append("<tr>");
			// startDate.get(Calendar.MONTH);
			for (int i = 1; i < day1_7; i++) {
				calendarHtml.append("<td></td>");
			}// frmDate.format(startDate.getTime())
			startDate.add(Calendar.MONTH, 1);
			startDate.add(Calendar.DATE, -1);
			// 총일자 구하기
			int totalDayCnt = startDate.get(Calendar.DATE);
			totalDayCnt = totalDayCnt
					+ (6 - startDate.get(Calendar.DAY_OF_WEEK) + 1) + 1;

			startDate.set(Calendar.DATE, 1);

			boolean chkDate = false;
			// 날짜 넣기
			for (int i = 1; i < totalDayCnt; i++) {
				if (i != 1) {
					startDate.add(Calendar.DATE, 1);
				}
				String rChkDate = "";

				if (vo.getReservation_dt().equals(
						frmDate.format(startDate.getTime()))) {
					rChkDate = "<img src='/camping/img/chkDate.png'/>";
				}

				String day = frmd.format(startDate.getTime());
				if (i != 1 && "1".equals(day)) {
					chkDate = true;
				}
				if (chkDate) {
					day = "";
				}
				if (1 == startDate.get(Calendar.DAY_OF_WEEK)) {
					// 일요일
					calendarHtml.append("<tr>");
					calendarHtml
							.append("<td class=\"sCalendar calRed bold\" rDate=\"");
					calendarHtml.append(frmDate.format(startDate.getTime()));
					calendarHtml.append("\">");
					calendarHtml.append(rChkDate);
					calendarHtml.append(day);
					calendarHtml.append("</td>");
				} else if (7 == startDate.get(Calendar.DAY_OF_WEEK)) {
					// 토요일
					calendarHtml
							.append("<td class=\"sCalendar calBlue bold\" rDate=\"");
					calendarHtml.append(frmDate.format(startDate.getTime()));
					calendarHtml.append("\">");
					calendarHtml.append(rChkDate);
					calendarHtml.append(day);
					calendarHtml.append("</td>");
					calendarHtml.append("</tr>");
				} else {
					// 평일
					calendarHtml
							.append("<td class=\"sCalendar bold\" rDate=\"");
					calendarHtml.append(frmDate.format(startDate.getTime()));
					calendarHtml.append("\">");
					calendarHtml.append(rChkDate);
					calendarHtml.append(day);
					calendarHtml.append("</td>");
				}
			}
			mav.addObject("leftCal", calendarHtml.toString());
		}

		List rooms = service.petc0101Q(vo);
		mav.addObject("rooms", rooms);
		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("reservation_dt", vo.getReservation_dt());
		return mav;
	}

	/**
	 * 예약 요금 구하기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0200Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}

		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");

		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		Calendar d1 = Calendar.getInstance();
		mav.addObject("nowDtAll", frmDtAll.format(d1.getTime()));
		List list = new ArrayList();

		String pg_no = vo.getPg_no();
		for (int i = 0; i < vo.getPr_nos().length; i++) {
			int yyyy = Integer.parseInt(vo.getReservation_dt().substring(0, 4));
			int mm = Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1;
			int dd = Integer.parseInt(vo.getReservation_dt().substring(6, 8));
			d1.set(yyyy, mm, dd);// 지정일.

			int pr_no = (int) vo.getPr_nos()[i];
			int man_cnt = (int) vo.getMan_cnts()[i];
			int chi_cnt = (int) vo.getChi_cnts()[i];
			int rsv_days = (int) vo.getRsv_days()[i];

			for (int j = 0; j < rsv_days; j++) {
				Map map = new HashMap();
				map.put("pr_no", pr_no);
				if (j != 0) {
					d1.add(Calendar.DATE, 1);
				}
				map.put("man_cnt", man_cnt);
				map.put("chi_cnt", chi_cnt);
				map.put("p_id", vo.getP_id());
				map.put("dy", d1.get(Calendar.DAY_OF_WEEK));
				map.put("reservation_dt", frmDate.format(d1.getTime()));

				list.add(map);
			}
		}
		vo.setNext_dates(list);

		int reservationCnt = service.petc0200Cnt(vo);
		if (reservationCnt > 0) {
			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc0101Q.do?p_id=" + vo.getP_id()
					+ "&reservation_dt=" + vo.getReservation_dt() + "&pg_no="
					+ vo.getPg_no());
			mav.addObject("msg", "예약이 완료된 객실이 있습니다");
			return mav;
		}

		List rooms = service.petc0200Rooms(vo);
		int totalPay = 0;
		for (int i = 0; i < rooms.size(); i++) {
			Map map = (Map) rooms.get(i);
			String busy_type = (String) map.get("busy_type");
			if ("".equals(map.get("busy_type"))) {
				if ("5".equals(map.get("dy"))) {// 금요일
					busy_type = "0102";
				} else if ("6".equals(map.get("dy"))) {// 토요일
					busy_type = "0103";
				} else {
					busy_type = "0101";
				}
			}

			int basePay = 0;
			// 기본요금 설정
			if ("0101".equals(busy_type)) {
				basePay = (int) map.get("busy_1_base");
			} else if ("0102".equals(busy_type)) {
				basePay = (int) map.get("busy_1_fri");
			} else if ("0103".equals(busy_type)) {
				basePay = (int) map.get("busy_1_sat");
			} else if ("0104".equals(busy_type)) {
				basePay = (int) map.get("busy_2_base");
			} else if ("0105".equals(busy_type)) {
				basePay = (int) map.get("busy_2_fri");
			} else if ("0106".equals(busy_type)) {
				basePay = (int) map.get("busy_2_sat");
			} else if ("0107".equals(busy_type)) {
				basePay = (int) map.get("busy_3_base");
			} else if ("0108".equals(busy_type)) {
				basePay = (int) map.get("busy_3_fri");
			} else if ("0109".equals(busy_type)) {
				basePay = (int) map.get("busy_3_sat");
			}
			basePay = basePay * 1000;
			map.put("basePay", basePay);

			totalPay += basePay;
			// 할인요금
			if (Integer.parseInt(map.get("pm_dc_m").toString()) != 0
					|| Integer.parseInt(map.get("pm_per").toString()) != 0) {
				if (Integer.parseInt(map.get("pm_dc_m").toString()) != 0) {
					int minusPay = Integer.parseInt(map.get("pm_dc_m")
							.toString());
					map.put("minusPay", minusPay);
					totalPay += minusPay;
				} else {
					int minusPay = Integer.parseInt(String.valueOf(Math
							.round((basePay * (0.01 * Integer.parseInt(map.get(
									"pm_per").toString()))))));
					map.put("minusPay", minusPay);
					totalPay += minusPay;
				}
			} else {
				map.put("minusPay", 0);
			}

			// 추가비용
			int addPay = 0;

			int use_man_cnt = Integer.parseInt(map.get("use_man_cnt")
					.toString());
			int use_max_cnt = Integer.parseInt(map.get("use_max_cnt")
					.toString());

			int man_cnt = Integer.parseInt(map.get("man_cnt").toString());
			int chi_cnt = Integer.parseInt(map.get("chi_cnt").toString());

			int aCnt = man_cnt - use_man_cnt;
			int add_usr_pay = Integer.parseInt(map.get("add_usr_pay")
					.toString()) * 1000;
			int add_child_pay = Integer.parseInt(map.get("add_child_pay")
					.toString()) * 1000;

			if (aCnt < 0) {
				addPay += Math.abs(aCnt * add_child_pay) ;
			} else {
				addPay += aCnt * add_usr_pay;
				addPay += chi_cnt * add_child_pay;
			}
			totalPay += addPay;
			map.put("addPay", addPay);
		}

		COMAVo codeVo = new COMAVo();
		// 전화번호
		codeVo.setCode_p_no("02");
		mav.addObject("code1List", comaService.coma104Q(codeVo));
		// 이메일
		codeVo.setCode_p_no("03");
		mav.addObject("code2List", comaService.coma104Q(codeVo));

		mav.addObject("rooms", rooms);
		mav.addObject("serviceList", service.pere200Q(vo));
		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("reservation_dt", vo.getReservation_dt());

		List aList = petiService.peti300_1Q(petiVo);

		List aList1 = new ArrayList();
		List aList2 = new ArrayList();
		List aList3 = new ArrayList();
		List aList4 = new ArrayList();

		if (aList != null && 0 < aList.size()) {
			for (int i = 0; i < aList.size(); i++) {
				Map map = (Map) aList.get(i);
				if ("1".equals(map.get("paa_type"))) {
					// 계좌
					aList1.add(map);
				} else if ("2".equals(map.get("paa_type"))) {
					// 픽업장소
					aList2.add(map);
				} else if ("3".equals(map.get("paa_type"))) {
					// 픽업정보
					aList3.add(map);
				} else if ("4".equals(map.get("paa_type"))) {
					// 도착시간
					aList4.add(map);
				}
			}
		}
		mav.addObject("aList1", aList1);
		mav.addObject("aList2", aList2);
		mav.addObject("aList3", aList3);
		mav.addObject("aList4", aList4);

		mav.addObject("p_id", vo.getP_id());

		// 환불규정
		mav.addObject("refundList", service.pere202_3Q(vo));
		// pg_no
		mav.addObject("pg_no", pg_no);

		// 부가서비스 가져오기
		mav.addObject("serviceList", service.pere200Q(vo));

//		연박할인 금액설정
		int rrr_pay = 0;

		for (int i = 0; i < vo.getPr_nos().length; i++) {
			int pr_no = (int) vo.getPr_nos()[i];
			int rsv_days = (int) vo.getRsv_days()[i];
			
			Map paramMap = new HashMap();
			paramMap.put("pr_no", pr_no);
			paramMap.put("reservation_dt", vo.getReservation_dt());
			paramMap.put("rsv_day", rsv_days);
			paramMap.put("p_id", vo.getP_id());
			rrr_pay += service.petc0200RelayQ(paramMap);

		}
//		List relayList = service.pere200_4Q(vo);
//		
//		String sPmDt = "";
//		int sPrNo = 0;
//		String sReservationDt = "";
//		Boolean bChkrr = false;
//		int mRrrPay=0;
//		for(int i = 0;i < relayList.size();i++){
//			Map rrData = (Map) relayList.get(i);
//			
//			String mPmDt = rrData.get("pm_dt").toString();
//			int mPrNo = Integer.parseInt(rrData.get("pr_no").toString());
//			String mReservationDt = rrData.get("reservation_dt").toString();
//			
//			
//			if(sReservationDt.equals(mReservationDt) && mPrNo == sPrNo){
//				
//			}else{
//				
//				if(bChkrr){
//					rrr_pay +=mRrrPay;
//				}
//				bChkrr = false;
//			}
//			mRrrPay = Integer.parseInt(rrData.get("rrr_pay").toString());
//			sReservationDt = mReservationDt;
//			sPrNo = mPrNo;
//			
//			Boolean mChkrr =false;
//			for(int j = 0; j < list.size();j++){
//				Map lData = (Map) list.get(j);
//				int lPrNo = Integer.parseInt(lData.get("pr_no").toString());
//				String lReservationDt = lData.get("reservation_dt").toString();
//
//				if(lPrNo == mPrNo
//						&& lReservationDt.equals(mPmDt)
//						){
//					bChkrr = true;
//					mChkrr = true;
//					break;
//				}
//			}
//			if(!mChkrr){
//				bChkrr = false;
//			}
//			
//		}
//		if(bChkrr){
//			rrr_pay +=mRrrPay;
//		}
//		연박할인 금액
		mav.addObject("rrr_pay", rrr_pay);
		//기본요금
		mav.addObject("b_pay", totalPay);
		// 총 비용
		mav.addObject("totalPay", totalPay-rrr_pay);
		
		return mav;
	}

	/**
	 * 사용자 예약
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc0201T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		ModelAndView mav = new ModelAndView();

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		// 기본 예약상태로 저장함
		vo.setRm_status("R");

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy-MM-dd(E)");

		Calendar d1 = Calendar.getInstance();

		List list = new ArrayList();
		// 객실 저장목록
		List returnList = new ArrayList();

		String smsRoom_nm = "";
		String smsReservation_dt = "";
		String smsReg_dt = frmDtAll.format(d1.getTime());

		String pg_no = vo.getPg_no();
		for (int i = 0; i < vo.getPr_nos().length; i++) {
			int yyyy = Integer.parseInt(vo.getReservation_dts()[i].substring(0,
					4));
			int mm = Integer.parseInt(vo.getReservation_dts()[i]
					.substring(4, 6)) - 1;
			int dd = Integer.parseInt(vo.getReservation_dts()[i]
					.substring(6, 8));
			d1.set(yyyy, mm, dd);// 지정일.

			int pr_no = (int) vo.getPr_nos()[i];
			int man_cnt = (int) vo.getMan_cnts()[i];
			int chi_cnt = (int) vo.getChi_cnts()[i];
			// int rsv_days = (int) vo.getRsv_days()[i];

			Map map = new HashMap();
			map.put("pr_no", pr_no);

			map.put("man_cnt", man_cnt);
			map.put("chi_cnt", chi_cnt);
			map.put("p_id", vo.getP_id());
			map.put("dy", d1.get(Calendar.DAY_OF_WEEK));
			map.put("reservation_dt", frmDate.format(d1.getTime()));

			list.add(map);
		}
		vo.setNext_dates(list);

		int reservationCnt = service.petc0200Cnt(vo);
		if (reservationCnt > 0) {
			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc0101Q.do?p_id=" + vo.getP_id()
					+ "&reservation_dt=" + vo.getReservation_dt() + "&pg_no="
					+ vo.getPg_no());
			mav.addObject("msg", "예약이 완료된 객실이 있습니다");
			return mav;
		}

		List rooms = service.petc0200Rooms(vo);
		int totalPay = 0;
		int iRoomCnt = 0;
		int iBak = 0;
		// data.put("smsRoomCnt",iRoomCnt);
		// data.put("smsBak",iBak);
		int pr_no = 99999999;
		for (int i = 0; i < rooms.size(); i++) {
			iBak++;
			Map map = (Map) rooms.get(i);
			int pPr_no = Integer.parseInt(map.get("pr_no").toString());
			if (pr_no != pPr_no) {
				pr_no = pPr_no;
				iRoomCnt++;
			}
			if (i == 0) {
				String smsRdt = (String) map.get("reservation_dt");
				smsRoom_nm = (String) map.get("room_nm");
				smsReservation_dt = smsRdt.substring(0, 4) + "-"
						+ smsRdt.substring(4, 6) + "-" + smsRdt.substring(6, 8);
			}
			String busy_type = (String) map.get("busy_type");
			if ("".equals(map.get("busy_type"))) {
				if ("5".equals(map.get("dy"))) {// 금요일
					busy_type = "0102";
				} else if ("6".equals(map.get("dy"))) {// 토요일
					busy_type = "0103";
				} else {
					busy_type = "0101";
				}
			}

			int basePay = 0;
			// 기본요금 설정
			if ("0101".equals(busy_type)) {
				basePay = (int) map.get("busy_1_base");
			} else if ("0102".equals(busy_type)) {
				basePay = (int) map.get("busy_1_fri");
			} else if ("0103".equals(busy_type)) {
				basePay = (int) map.get("busy_1_sat");
			} else if ("0104".equals(busy_type)) {
				basePay = (int) map.get("busy_2_base");
			} else if ("0105".equals(busy_type)) {
				basePay = (int) map.get("busy_2_fri");
			} else if ("0106".equals(busy_type)) {
				basePay = (int) map.get("busy_2_sat");
			} else if ("0107".equals(busy_type)) {
				basePay = (int) map.get("busy_3_base");
			} else if ("0108".equals(busy_type)) {
				basePay = (int) map.get("busy_3_fri");
			} else if ("0109".equals(busy_type)) {
				basePay = (int) map.get("busy_3_sat");
			}
			basePay = basePay * 1000;
			map.put("basePay", basePay);

			totalPay += basePay;
			// 할인요금
			int minusPay = 0;
			if (Integer.parseInt(map.get("pm_dc_m").toString()) != 0
					|| Integer.parseInt(map.get("pm_per").toString()) != 0) {
				if (Integer.parseInt(map.get("pm_dc_m").toString()) != 0) {
					minusPay = Integer.parseInt(map.get("pm_dc_m").toString());
					map.put("minusPay", minusPay);
					totalPay += minusPay;
				} else {
					minusPay = Integer.parseInt(String.valueOf(Math
							.round((basePay * (0.01 * Integer.parseInt(map.get(
									"pm_per").toString()))))));
					map.put("minusPay", minusPay);
					totalPay += minusPay;
				}
			} else {
				map.put("minusPay", 0);
			}

			// 추가비용
			int addPay = 0;

			int use_man_cnt = Integer.parseInt(map.get("use_man_cnt")
					.toString());
			int use_max_cnt = Integer.parseInt(map.get("use_max_cnt")
					.toString());

			int man_cnt = Integer.parseInt(map.get("man_cnt").toString());
			int chi_cnt = Integer.parseInt(map.get("chi_cnt").toString());

			int aCnt = man_cnt - use_man_cnt;
			int add_usr_pay = Integer.parseInt(map.get("add_usr_pay")
					.toString()) * 1000;
			int add_child_pay = Integer.parseInt(map.get("add_child_pay")
					.toString()) * 1000;

			if (aCnt < 0) {
				addPay += (add_child_pay + aCnt) * add_child_pay;
			} else {
				addPay += aCnt * add_usr_pay;
				addPay += chi_cnt * add_child_pay;
			}
			totalPay += addPay;
			map.put("addPay", addPay);
			Map returnMap = new HashMap();

			returnMap.put("p_id", vo.getP_id());
			returnMap.put("reservation_dt", map.get("reservation_dt"));
			returnMap.put("pr_no",
					Integer.parseInt(map.get("pr_no").toString()));
			// returnMap.put("rm_no", map.get(""));
			returnMap.put("man_cnt",
					Integer.parseInt(map.get("man_cnt").toString()));
			returnMap.put("chi_cnt",
					Integer.parseInt(map.get("chi_cnt").toString()));
			returnMap.put("base_pay", basePay);
			returnMap.put("add_pay", addPay);

			returnMap.put("dc_pay", minusPay);
			returnMap.put("rm_status", vo.getRm_status());
			returnMap.put("total_pay", totalPay);

			returnMap.put("pay", basePay);
			returnMap.put("pay_man_m", addPay);

			returnList.add(returnMap);
		}
		// 객실비용 구매비용 조회
		// totalPay

		int servicePay = 0;
		// 서비스 비용 조회
		List rtAddSvcList = new ArrayList();
		// 부가서비스 가격 조회
		if (vo.getAs_no_idxs() != null && vo.getAs_no_idxs().length > 0) {
			List addServiceList = service.pere200Q(vo);
			for (int i = 0; i < vo.getAs_no_idxs().length; i++) {
				int as_no = (int) vo.getAs_nos()[vo.getAs_no_idxs()[i]];
				int use_cnt = (int) vo.getUse_cnts()[vo.getAs_no_idxs()[i]];
				String req_msg = vo.getReq_msgs()[vo.getAs_no_idxs()[i]];

				for (int jj = 0; jj < addServiceList.size(); jj++) {
					Map map = (Map) addServiceList.get(jj);
					int mAs_no = (Integer) map.get("as_no");
					if (mAs_no == as_no) {
						int as_pay = (Integer) map.get("as_pay");
						servicePay += (use_cnt * as_pay);
						map.put("use_cnt", use_cnt);
						map.put("totalPay", (use_cnt * as_pay));
						map.put("req_msg", req_msg);
						rtAddSvcList.add(map);
						break;
					}
				}
			}
		}

		// System.out.println("구매 총 비용 : "+ totalPay+servicePay);
		Map data = new HashMap();
		data.put("paramMap", vo);
		data.put("list", returnList);
		// 부가서비스 리턴
		data.put("rtAddSvcList", rtAddSvcList);
		data.put("smsRoomCnt", iRoomCnt);
		
		// 객실명
		data.put("smsRoom_nm", smsRoom_nm);
		// 예약일
		data.put("smsReservation_dt", smsReservation_dt);
		// 등록일
		data.put("smsReg_dt", smsReg_dt);
		// 숙박일
		data.put("smsBak", iBak);
		
		int rrr_pay = 0;
		List relayList = service.pere200_4Q(vo);
		
		String sPmDt = "";
		int sPrNo = 0;
		String sReservationDt = "";
		Boolean bChkrr = false;
		int mRrrPay=0;
		for(int i = 0;i < relayList.size();i++){
			Map rrData = (Map) relayList.get(i);
			
			String mPmDt = rrData.get("pm_dt").toString();
			int mPrNo = Integer.parseInt(rrData.get("pr_no").toString());
			String mReservationDt = rrData.get("reservation_dt").toString();
			
			if(sReservationDt.equals(mReservationDt)  && mPrNo == sPrNo){
				
			}else{
				
				if(bChkrr){
					rrr_pay +=mRrrPay;
				}
				bChkrr = false;
			}
			mRrrPay = Integer.parseInt(rrData.get("rrr_pay").toString());
			sReservationDt = mReservationDt;
			sPrNo = mPrNo;
			
			Boolean mChkrr =false;
			for(int j = 0; j < list.size();j++){
				Map lData = (Map) list.get(j);
				int lPrNo = Integer.parseInt(lData.get("pr_no").toString());
				String lReservationDt = lData.get("reservation_dt").toString();

				
				
				if(lPrNo == mPrNo
						&& lReservationDt.equals(mPmDt)
						){
					bChkrr = true;
					mChkrr = true;
					break;
				}
			}
			if(!mChkrr){
				bChkrr = false;
			}
			
		}
		if(bChkrr){
			rrr_pay +=mRrrPay;
		}
//		연박할인 금액
		data.put("rrr_pay", rrr_pay);
		data.put("totalPay", totalPay-rrr_pay);
		service.pere204T(data);

		mav.setViewName("/common/close");
		mav.addObject("redirect", "./petc0101Q.do?p_id=" + vo.getP_id()
				+ "&reservation_dt=" + smsReservation_dt.replace("-", "")
				+ "&pg_no=" + vo.getPg_no());
		mav.addObject("msg", "예약되었습니다");

		return mav;
	}

	/**
	 * 관리자 예약현황
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc1001Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}

		ModelAndView mav = new ModelAndView();
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);


		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));


		
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		reservation_use_month = reservation_use_month - 1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt(frmDate1.format(maxMonthChk
				.getTime().getTime()));
//		if (chkConditionMonth > maxMonthNum) {
//			vo.setReservation_dt(maxMonthNum + "01");
//			chkConditionMonth = maxMonthNum;
//			mav = new ModelAndView("/common/close");
//			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
//			mav.addObject("msg", (reservation_use_month + 1)
//					+ "개월 이상은 예약이 불가능합니다.");
//			return mav;
//		}
		
		int group_cnt = Integer.parseInt(pensionInfo.get("group_cnt")
				.toString());
		if (group_cnt < 2) {
			int pg_no = Integer
					.parseInt(pensionInfo.get("group_no").toString());
			mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./petc1006Q.do?p_id=" + vo.getP_id()
					+ "&pg_no=" + pg_no);
			return mav;
		}

		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");
		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		mav.addObject("nDtAll", frmDtAll.format(d1.getTime()));

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}

		Calendar destDate = Calendar.getInstance();

		destDate.set(Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
				Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1, 1);

		Calendar startDate = (Calendar) destDate.clone();
		destDate.set(Calendar.DATE,
				destDate.getActualMaximum(Calendar.DAY_OF_MONTH));
		// 해당월이 몇주가 나오는지
		int week = destDate.get(Calendar.WEEK_OF_MONTH);

		Calendar lastDate = Calendar.getInstance();

		// 해당월에 추가되야할 날수
		int addDate1 = 7 - destDate.get(Calendar.DAY_OF_WEEK);

		destDate.add(Calendar.DATE, addDate1);
		lastDate = (Calendar) destDate.clone();

		Calendar addDt = (Calendar) startDate.clone();
		List dateList = new ArrayList();
		long b = (lastDate.getTimeInMillis() - startDate.getTimeInMillis()) / 1000;
		int dateCha = (int) (b / (60 * 60 * 24));
		dateList.add(frmDate.format(addDt.getTime()));
		for (int i = 0; i < dateCha; i++) {
			addDt.add(Calendar.DATE, 1);
			dateList.add(frmDate.format(addDt.getTime()));
		}
		vo.setList(dateList);

		List groupList = service.petc100Q(vo);

		StringBuffer textCal = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();

		int sevenChk = 0;

		// 달력 그리기 시작
		// 텍스트 기반
		Calendar stDt = (Calendar) startDate.clone();
		stDt.set(Calendar.DATE, 1);

		textCal.append("<tr>");
		int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
		for (int i = 0; i < addDate; i++) {
			textCal.append("<td></td>");
			sevenChk++;
		}
		// 빈데이터 처리
		int beforeDt = Integer.parseInt(vo.getReservation_dt().substring(6, 8));
		if (!vo.getReservation_dt().substring(0, 6)
				.equals(frmMonth.format(Calendar.getInstance().getTime()))) {
			beforeDt = 0;
		}

		int listChk = 0;
		// 데이터 있는 자료 처리
		for (int i = 0; i < dateList.size(); i++) {
			sevenChk++;
			tdHtml.setLength(0);

			String htmlDt = frmDate.format(stDt.getTime());
			String _busy_type= "";
			for (int j = listChk; j < groupList.size(); j++) {
				Map map = (Map) groupList.get(j);
				int relay_day = Integer.parseInt(map.get("relay_day")
						.toString());
				listChk = j;
				int ready_cnt = Integer.parseInt(map.get("ready_cnt")
						.toString());
				if (htmlDt.equals(map.get("dt"))) {

					String img = "icon_green.jpg";
					int _cnt = Integer.parseInt(map.get("cnt").toString());
					int _group_cnt = Integer.parseInt(map.get("group_cnt")
							.toString());
					if (_cnt == _group_cnt) {
						img = "icon_red.jpg";
					}
					_busy_type=map.get("busy_type").toString();
					tdHtml.append("<li>");
					tdHtml.append("<a href=\"#\" onclick=\"goReserrvation('"
							+ map.get("p_id") + "',this,'" + map.get("dt")
							+ "','" + map.get("pg_no") + "');\"> ");
					tdHtml.append("<img src=\"/camping/img/" + img + "\" /> ");

					tdHtml.append(map.get("group_nm") + "(" + _cnt + "/"
							+ _group_cnt + ")");
					if (relay_day != 0) {
						tdHtml.append(" (부분" + relay_day + "박예약)");
					}
					tdHtml.append("</a>");
					if (ready_cnt > 0) {
						// pere700Q.do?p_id=aaa
						tdHtml.append(" <a href=\"./pere700Q.do?p_id=");
						tdHtml.append(vo.getP_id());
						tdHtml.append("&reservation_dt=");// "대기자");
						tdHtml.append(map.get("dt"));
						tdHtml.append("\"><span class='calRed'>대기자</span>");
						tdHtml.append("</a>");
					}
					tdHtml.append("</li>");
					// ptrend 빨강, ptrnomal 검정, ptrstandby 파랑
				} else {
					break;
				}
			}

			String roomListT = tdHtml.toString();
			if (group_cnt <= 4) {
				roomListT = "<li>&nbsp;</li>" + roomListT + "<li>&nbsp;</li>";
			}

			textCal.append("<td valign='top'>");

			int dow = stDt.get(Calendar.DAY_OF_WEEK);

			// 일 백그라운드
			String dayBackClass = "calJuganBack";
			String dayFontClass = "fnt18";
			// 객실 백그라운드
			String roomBackClass = "";

			if (dow == 7) {// 토요일
				dayBackClass = "calJuganBackSat";
				dayFontClass = "calBlue";
				roomBackClass = "calBackSat";
			} else if (dow == 1) {// 일요일
				dayBackClass = "calJuganBackSun";
				dayFontClass = "calRed";
				roomBackClass = "calBackSun";
			}
			if(dow == 6){
				if("".equals(_busy_type)){_busy_type="0102";}	
			}else if(dow == 7){
				if("".equals(_busy_type)){_busy_type="0103";}
			}else{
				if("".equals(_busy_type)){_busy_type="0101";}
			}

			textCal.append("<div class=\"");
			textCal.append(dayBackClass);
			textCal.append("\">");
			
			textCal.append("<table width='100%' border=0 cellSpacing=0 cellPadding=0><tr>");
			textCal.append("<td class=\"bold\" style='border:0;width:70%' width='70%'>["+getBusyTypeNm( _busy_type)+"]</td>");
			
			if("1".equals(frmd.format(stDt.getTime()))){

				textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "<strong></td>");
			}else{
				textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+ frmd.format(stDt.getTime()) + "<strong></td>");
			}

			textCal.append("</tr></table>");
			
//			if("1".equals(frmd.format(stDt.getTime()))){
//				textCal.append("	<strong class=\"" + dayFontClass + "\">"
//						+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "</strong>");
//			}else{
//				textCal.append("	<strong class=\"" + dayFontClass + "\">"
//						+ frmd.format(stDt.getTime()) + "</strong>");
//			}
			
			textCal.append("</div>");

			textCal.append("	<div class=\"\">");
			textCal.append("		<ul>");
			textCal.append(roomListT);
			textCal.append("		</ul>");
			textCal.append("	</div>");
			textCal.append("</td>");

			stDt.add(Calendar.DATE, 1);
			if (sevenChk % 7 == 0) {
				textCal.append("</tr>");
				textCal.append("<tr>");
			}
		}
		// 마무리
		textCal.append("</tr>");
		// 달력 그리기 종료

		mav.addObject("txtCal", textCal.toString());
		// mav.addObject("groupList", groupList);
		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("reservation_dt", vo.getReservation_dt());

		return mav;
	}

	/**
	 * 관리자 화면 사이트 선택
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */

	@RequestMapping
	public ModelAndView petc1002Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		

		ModelAndView mav = new ModelAndView();
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);


		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmDate1 = new SimpleDateFormat("yyyyMM");

		Calendar d1 = Calendar.getInstance();
		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}
		int chkMonth = Integer
				.parseInt(frmDate1.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));

		// 이전달 조회 금지
		if (chkMonth > chkConditionMonth) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;
			mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
			return mav;
		}

		
		String p_ico_yn = (String) pensionInfo.get("p_ico_yn");
		String p_id = (String) pensionInfo.get("p_id");
		String friday_yn = (String) pensionInfo.get("friday_yn");

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		reservation_use_month = reservation_use_month - 1;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt(frmDate1.format(maxMonthChk
				.getTime().getTime()));
		if (chkConditionMonth > maxMonthNum) {
			vo.setReservation_dt(maxMonthNum + "01");
			chkConditionMonth = maxMonthNum;
			mav = new ModelAndView("/common/close");
			mav.addObject("redirect", "./petc100Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", (reservation_use_month + 1)
					+ "개월 이상은 예약이 불가능합니다.");
			return mav;
		}
				
		petiVo.setP_id(vo.getP_id());
		
		if ("I".equals(pensionInfo.get("view_type2"))) {
			// 이미지일경우
			mav = new ModelAndView("usr/pe/re/petc1002_IQ");
		} else {
			mav = new ModelAndView("usr/pe/re/petc1002_TQ");
		}

		Calendar destDate = Calendar.getInstance();
		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");

		if (vo.getReservation_dt() == null) {
			vo.setReservation_dt(frmDate.format(destDate.getTime()));
		}

		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		// 오늘 설정
		mav.addObject("nDtAll", frmDtAll.format(destDate.getTime()));

		destDate.set(Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
				Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
				Integer.parseInt(vo.getReservation_dt().substring(6, 8)));
		// 예약한 날
		mav.addObject("rDtAll", frmDtAll.format(destDate.getTime()));

		Calendar cReservationDt = (Calendar) destDate.clone();

		destDate.add(Calendar.DATE, 7);
		vo.setReservation_next_dt(frmDate.format(destDate.getTime()));

		if ("I".equals(pensionInfo.get("view_type2"))) {
			// 이미지일경우

		} else {
			// 텍스트일경우
			List aList = petiService.peti300_1Q(petiVo);

			List aList1 = new ArrayList();
			List aList2 = new ArrayList();
			List aList3 = new ArrayList();
			List aList4 = new ArrayList();

			if (aList != null && 0 < aList.size()) {
				for (int i = 0; i < aList.size(); i++) {
					Map map = (Map) aList.get(i);
					if ("1".equals(map.get("paa_type"))) {
						// 계좌
						aList1.add(map);
					} else if ("2".equals(map.get("paa_type"))) {
						// 픽업장소
						aList2.add(map);
					} else if ("3".equals(map.get("paa_type"))) {
						// 픽업정보
						aList3.add(map);
					} else if ("4".equals(map.get("paa_type"))) {
						// 도착시간
						aList4.add(map);
					}
				}
			}
			mav.addObject("aList1", aList1);
			mav.addObject("aList2", aList2);
			mav.addObject("aList3", aList3);
			mav.addObject("aList4", aList4);

			// 달력설정
			// Calendar startDt = (Calendar) cReservationDt.clone();
			// startDt.set(Calendar.DATE, 1);

			Calendar startDate = (Calendar) cReservationDt.clone();
			startDate.set(Calendar.DATE, 1);
			// 시작요일확인
			int day1_7 = startDate.get(Calendar.DAY_OF_WEEK);
			StringBuffer calendarHtml = new StringBuffer();
			calendarHtml.append("<tr>");
			// startDate.get(Calendar.MONTH);
			for (int i = 1; i < day1_7; i++) {
				calendarHtml.append("<td></td>");
			}// frmDate.format(startDate.getTime())
			startDate.add(Calendar.MONTH, 1);
			startDate.add(Calendar.DATE, -1);
			// 총일자 구하기
			int totalDayCnt = startDate.get(Calendar.DATE);
			totalDayCnt = totalDayCnt
					+ (6 - startDate.get(Calendar.DAY_OF_WEEK) + 1) + 1;

			startDate.set(Calendar.DATE, 1);

			boolean chkDate = false;
			// 날짜 넣기
			for (int i = 1; i < totalDayCnt; i++) {
				if (i != 1) {
					startDate.add(Calendar.DATE, 1);
				}
				String rChkDate = "";

				if (vo.getReservation_dt().equals(
						frmDate.format(startDate.getTime()))) {
					rChkDate = "<img src='/camping/img/chkDate.png'/>";
				}

				String day = frmd.format(startDate.getTime());
				if (i != 1 && "1".equals(day)) {
					chkDate = true;
				}
				if (chkDate) {
					day = "";
				}
				if (1 == startDate.get(Calendar.DAY_OF_WEEK)) {
					// 일요일
					calendarHtml.append("<tr>");
					calendarHtml
							.append("<td class=\"sCalendar calRed bold\" rDate=\"");
					calendarHtml.append(frmDate.format(startDate.getTime()));
					calendarHtml.append("\">");
					calendarHtml.append(rChkDate);
					calendarHtml.append(day);
					calendarHtml.append("</td>");
				} else if (7 == startDate.get(Calendar.DAY_OF_WEEK)) {
					// 토요일
					calendarHtml
							.append("<td class=\"sCalendar calBlue bold\" rDate=\"");
					calendarHtml.append(frmDate.format(startDate.getTime()));
					calendarHtml.append("\">");
					calendarHtml.append(rChkDate);
					calendarHtml.append(day);
					calendarHtml.append("</td>");
					calendarHtml.append("</tr>");
				} else {
					// 평일
					calendarHtml
							.append("<td class=\"sCalendar bold\" rDate=\"");
					calendarHtml.append(frmDate.format(startDate.getTime()));
					calendarHtml.append("\">");
					calendarHtml.append(rChkDate);
					calendarHtml.append(day);
					calendarHtml.append("</td>");
				}
			}
			mav.addObject("leftCal", calendarHtml.toString());
		}

		List rooms = service.petc0101Q(vo);
		mav.addObject("rooms", rooms);
		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("reservation_dt", vo.getReservation_dt());
		return mav;
	}

	/**
	 * 그룹이 하나일 경우 테이블로 보여주기
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc1003Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		ModelAndView mav = new ModelAndView();
		// if("T".equals(pensionInfo.get("view_type1"))){
		// mav = new ModelAndView("usr/pe/re/petc100_TQ");
		// }else{
		// //이미지 기반 달력
		// mav = new ModelAndView("usr/pe/re/petc100_IQ");
		// }

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");
		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		Calendar d1 = Calendar.getInstance();
		mav.addObject("nDtAll", frmDtAll.format(d1.getTime()));

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}

		int chkMonth = Integer
				.parseInt(frmMonth.format(d1.getTime().getTime()));
		int chkConditionMonth = Integer.parseInt(vo.getReservation_dt()
				.substring(0, 6));
		
		// 이전달 조회 금지
		if (chkMonth > chkConditionMonth) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
			chkConditionMonth = chkMonth;

			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc1003Q.do?p_id=" + vo.getP_id());
			mav.addObject("msg", "이전달은 예약이 불가능합니다.");
			return mav;
		}
		

		// 설정한 달 이상 조회금지
		int reservation_use_month = (Integer) pensionInfo
				.get("reservation_use_month");
		if (reservation_use_month == 0) {
			reservation_use_month = 13; // 예약 최대기간 1년1개월
		}
		
		reservation_use_month = reservation_use_month;
		Calendar maxMonthChk = Calendar.getInstance();
		maxMonthChk.add(Calendar.MONTH, reservation_use_month);
		int maxMonthNum = Integer.parseInt(frmMonth.format(maxMonthChk
				.getTime().getTime()));
		if (chkConditionMonth > maxMonthNum) {
			mav.setViewName("/common/close");
			mav.addObject("redirect", "./petc1003Q.do?p_id=" + vo.getP_id()
					+ "&reservation_dt=" + maxMonthNum + "01");
			mav.addObject("msg", (reservation_use_month) + "개월 이상은 예약이 불가능합니다.");
			return mav;
		}

		Calendar destDate = Calendar.getInstance();

		if (!vo.getReservation_dt().substring(0, 6)
				.equals(frmMonth.format(destDate.getTime()))) {
			destDate.set(
					Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
					Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
					1);
		} else {
			destDate.set(
					Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
					Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
					Integer.parseInt(vo.getReservation_dt().substring(6, 8)));
		}

		Calendar startDate = (Calendar) destDate.clone();
		destDate.set(Calendar.DATE,
				destDate.getActualMaximum(Calendar.DAY_OF_MONTH));
		// 해당월이 몇주가 나오는지
		int week = destDate.get(Calendar.WEEK_OF_MONTH);

		Calendar lastDate = Calendar.getInstance();

		if ("D".equals(pensionInfo.get("reservation_cal"))) {
			// 일반

			// 해당월에 추가되야할 날수
			int addDate = 7 - destDate.get(Calendar.DAY_OF_WEEK);

			destDate.add(Calendar.DATE, addDate);
			lastDate = (Calendar) destDate.clone();
		} else {
			// 이월

			Calendar nowDt = (Calendar) startDate.clone();
			// 해당월에 추가되야할 날수
			int addDate = 7 - startDate.get(Calendar.DAY_OF_WEEK);
			addDate = addDate + (7 * (week - 1));
			nowDt.add(Calendar.DATE, addDate);
			lastDate = (Calendar) nowDt.clone();
		}
		// frmDate.format(startDate.getTime())
		Calendar addDt = (Calendar) startDate.clone();
		List dateList = new ArrayList();
		long b = (lastDate.getTimeInMillis() - startDate.getTimeInMillis()) / 1000;
		int dateCha = (int) (b / (60 * 60 * 24));
		dateList.add(frmDate.format(addDt.getTime()));
		for (int i = 0; i < dateCha; i++) {
			addDt.add(Calendar.DATE, 1);
			dateList.add(frmDate.format(addDt.getTime()));
		}
		vo.setList(dateList);

		// 객실 목록
		List roomsList = service.pere101Q(vo);

		// 예약현황
		List reservationList = service.petc1003Q(vo);

		StringBuffer textCal = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();

		int sevenChk = 0;

		if ("D".equals(pensionInfo.get("reservation_cal"))) {
			// 일반
			Calendar stDt = (Calendar) startDate.clone();
			stDt.set(Calendar.DATE, 1);

			textCal.append("<tr>");
			int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
			for (int i = 0; i < addDate; i++) {
				textCal.append("<td></td>");
				sevenChk++;
			}
			// 빈데이터 처리
			int beforeDt = Integer.parseInt(vo.getReservation_dt().substring(6,
					8));
			if (!vo.getReservation_dt().substring(0, 6)
					.equals(frmMonth.format(Calendar.getInstance().getTime()))) {
				beforeDt = 0;
			}
			StringBuffer blankRooms = new StringBuffer();
			for (int i = 0; i < roomsList.size(); i++) {
				blankRooms.append("<li>&nbsp;</li>");
			}
			for (int i = 1; i < beforeDt; i++) {
				sevenChk++;

				textCal.append("<td valign='top'>");

				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}

				textCal.append("<div class=\"tr ");
				textCal.append(dayBackClass);
				textCal.append("\">");

				textCal.append("	<strong class=\"" + dayFontClass + "\">"
						+ frmd.format(stDt.getTime()) + "</strong>");
				textCal.append("</div>");

				textCal.append("	<div class=\"\">");
				textCal.append("		<ul>");
				textCal.append(blankRooms.toString());
				textCal.append("		</ul>");
				textCal.append("	</div>");

				textCal.append("</td>");

				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
			}

			long lDateCha = (lastDate.getTimeInMillis() - startDate
					.getTimeInMillis()) / 1000;
			int forCa = beforeDt + (int) (lDateCha / (60 * 60 * 24));

			int listIndex = 0;
			int listChk = 0;
			// 데이터 있는 자료 처리
			for (int i = beforeDt; i <= forCa; i++) {
				sevenChk++;
				tdHtml.setLength(0);

				String htmlDt = frmDate.format(stDt.getTime());

				for (int ii = 0; ii < roomsList.size(); ii++) {
					int dateNowNum = Integer.parseInt(frmDate.format(stDt
							.getTime()));

					Map proM = null;
					Map room = (Map) roomsList.get(ii);
					for (int j = listIndex; j < reservationList.size(); j++) {
						proM = (Map) reservationList.get(j);
						int dateNum = Integer.parseInt(proM.get(
								"reservation_dt").toString());
						if (dateNum == dateNowNum
								&& 
								Integer.toString((Integer)room.get("pr_no")).equals(
										Integer.toString((Integer)proM.get("pr_no")))
								) {
							listIndex = j;
							break;
						} else {
							proM = null;
						}
					}

					String site_size = "";// room.get("area_p")+""
					if (null != room.get("area_p")
							&& !"".equals(room.get("area_p"))) {
						site_size = "가로 " + room.get("area_p") + "m, 세로 "
								+ room.get("area_m") + "m";
					}

					String room_form = "";
					if (null != room.get("room_form")
							&& !"".equals(room.get("room_form"))) {
						room_form = "" + room.get("room_form");
					}

					if (proM == null) {
						// 요일체크
						int dayOfWeek = stDt.get(Calendar.DAY_OF_WEEK);

						String busy_type = "0101";
						int pm_pay = Integer.parseInt(room.get("busy_1_base")
								.toString()) * 1000;
						if (6 == dayOfWeek) {
							// 금요일
							busy_type = "0102";
							pm_pay = Integer.parseInt(room.get("busy_1_fri")
									.toString()) * 1000;
						} else if (7 == dayOfWeek) {
							// 토요일
							busy_type = "0103";
							pm_pay = Integer.parseInt(room.get("busy_1_sat")
									.toString()) * 1000;
						}

						tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
								+ room.get("p_id")
								+ "&reservation_dt="
								+ dateNowNum
								+ "&pg_no="
								+ room.get("pg_no")
								+ "&sel_pr_no="
								+ room.get("pr_no")
								+ "\" room_nm='"
								+ room.get("room_nm")
								+ "' pm_pay='"
								+ pm_pay
								+ "' reservation_nm='' busy_type_nm='"
								+ getBusyTypeNm(busy_type)
								+ "' rm_status=''  site_size=\""
								+ site_size
								+ "\" site_form=\""
								+ room_form
								+ "\"><img src=\"/camping/img/icon_green.jpg\">&nbsp;"
								+ room.get("room_nm") + "</a></li>");
					} else {
						String img = "icon_green.jpg";
						if ("C".equals(proM.get("rm_status"))) {
							img = "icon_red.jpg";
							tdHtml.append("<li class='liPop'><a class='calRed' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'  site_size=\""
									+ site_size
									+ "\" site_form=\""
									+ room_form
									+ "\"><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;완료["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else if ("R".equals(proM.get("rm_status"))) {
							img = "icon_blue.jpg";
							tdHtml.append("<li class='liPop'><a class='calBlue' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'  site_size=\""
									+ site_size
									+ "\" site_form=\""
									+ room_form
									+ "\"><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;대기["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else {
							tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
									+ room.get("p_id")
									+ "&reservation_dt="
									+ dateNowNum
									+ "&pg_no="
									+ room.get("pg_no")
									+ "&sel_pr_no="
									+ room.get("pr_no")
									+ "\" rm_status='' room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "'  site_size=\""
									+ site_size
									+ "\" site_form=\""
									+ room_form
									+ "\"><img src=\"/camping/img/"
									+ img
									+ "\">&nbsp;"
									+ room.get("room_nm")
									+ "</a></li>");
						}

					}
				}

				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}

				textCal.append("<td class=\"day23\" valign=\"top\" ");
				textCal.append("	id=\"day_" + htmlDt + "\">");

				textCal.append("<div class=\"tr ");
				textCal.append(dayBackClass);
				textCal.append("\">");
				
				if("1".equals(frmd.format(stDt.getTime()))){
					textCal.append("	<strong class=\"" + dayFontClass + "\">"
							+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "</strong>");
				}else{
					textCal.append("	<strong class=\"" + dayFontClass + "\">"
							+ frmd.format(stDt.getTime()) + "</strong>");
				}
				
				textCal.append("</div>");

				textCal.append("	<div class=\"" + roomBackClass + "\">");
				textCal.append("		<ul>");
				textCal.append(tdHtml.toString());

				textCal.append("		</ul>");
				textCal.append("	</div>");
				textCal.append("</td>");

				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
			}
			// 마무리
			textCal.append("</tr>");
		} else {
			// 이월
			Calendar stDt = (Calendar) startDate.clone();
			// stDt.set(Calendar.DATE, 1);
			// frmDate.format(stDt.getTime());
			textCal.append("<tr>");
			int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
			for (int i = 0; i < addDate; i++) {
				textCal.append("<td></td>");
				sevenChk++;
			}
			// 빈데이터 처리
			int beforeDt = Integer.parseInt(vo.getReservation_dt().substring(6,
					8));
			if (!vo.getReservation_dt().substring(0, 6)
					.equals(frmMonth.format(Calendar.getInstance().getTime()))) {
				beforeDt = 0;
			}

			long lDateCha = (lastDate.getTimeInMillis() - startDate
					.getTimeInMillis()) / 1000;
			int forCa = beforeDt + (int) (lDateCha / (60 * 60 * 24));

			int listChk = 0;

			int listIndex = 0;

			// reservationList
			// 데이터 있는 자료 처리
			for (int i = beforeDt; i <= forCa; i++) {
				sevenChk++;
				// tdHtml.setLength(0);
				// icon_green.jpg //신
				// icon_blue.jpg //대
				// icon_red.jpg //완
				String htmlDt = frmDate.format(stDt.getTime());
				tdHtml.setLength(0);
				String _busy_type= "";
				for (int ii = 0; ii < roomsList.size(); ii++) {
					int dateNowNum = Integer.parseInt(frmDate.format(stDt
							.getTime()));

					Map proM = null;
					Map room = (Map) roomsList.get(ii);
					for (int j = listIndex; j < reservationList.size(); j++) {
						proM = (Map) reservationList.get(j);
						int dateNum = Integer.parseInt(proM.get(
								"reservation_dt").toString());
						if (dateNum == dateNowNum
								&& 
								Integer.toString((Integer)room.get("pr_no")).equals(
										Integer.toString((Integer)proM.get("pr_no")))
								) {
							listIndex = j;
							break;
						} else {
							proM = null;
						}
					}
					if (proM == null) {
						// 요일체크
						int dayOfWeek = stDt.get(Calendar.DAY_OF_WEEK);

						String busy_type = "0101";
						int pm_pay = Integer.parseInt(room.get("busy_1_base")
								.toString()) * 1000;
						if (6 == dayOfWeek) {
							// 금요일
							busy_type = "0102";
							pm_pay = Integer.parseInt(room.get("busy_1_fri")
									.toString()) * 1000;
						} else if (7 == dayOfWeek) {
							// 토요일
							busy_type = "0103";
							pm_pay = Integer.parseInt(room.get("busy_1_sat")
									.toString()) * 1000;
						}

						tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
								+ room.get("p_id")
								+ "&reservation_dt="
								+ dateNowNum
								+ "&pg_no="
								+ room.get("pg_no")
								+ "&sel_pr_no="
								+ room.get("pr_no")
								+ "\" room_nm='"
								+ room.get("room_nm")
								+ "' pm_pay='"
								+ pm_pay
								+ "' reservation_nm='' busy_type_nm='"
								+ getBusyTypeNm(busy_type)
								+ "' rm_status=''><img src=\"/camping/img/icon_green.jpg\">&nbsp;"
								+ room.get("room_nm") + "</a></li>");
					} else {
						_busy_type=proM.get("busy_type").toString();
						String img = "icon_green.jpg";
						if ("C".equals(proM.get("rm_status"))) {
							img = "icon_red.jpg";
							tdHtml.append("<li class='liPop'><a class='calRed' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;완료["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else if ("R".equals(proM.get("rm_status"))) {
							img = "icon_blue.jpg";
							tdHtml.append("<li class='liPop'><a class='calBlue' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;대기["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else {
							tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
									+ room.get("p_id")
									+ "&reservation_dt="
									+ dateNowNum
									+ "&pg_no="
									+ room.get("pg_no")
									+ "&sel_pr_no="
									+ room.get("pr_no")
									+ "\" rm_status='' room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "'><img src=\"/camping/img/"
									+ img
									+ "\">&nbsp;"
									+ room.get("room_nm")
									+ "</a></li>");
						}

					}
				}

				String roomListT = tdHtml.toString();

				if (chkConditionMonth == maxMonthNum) {
					if(stDt.getTime().getTime() > maxMonthChk.getTime().getTime()){
						roomListT = "<li>&nbsp;</li>예약불가<li>&nbsp;</li>";
					}
				}
				
				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}
				if(dow == 6){
					if("".equals(_busy_type)){_busy_type="0102";}	
				}else if(dow == 7){
					if("".equals(_busy_type)){_busy_type="0103";}
				}else{
					if("".equals(_busy_type)){_busy_type="0101";}
				}

				textCal.append("<td class=\"day23\" valign=\"top\" ");
				textCal.append("	id=\"day_" + htmlDt + "\">");

				textCal.append("<div class=\"");
				textCal.append(dayBackClass);
				textCal.append("\">");


				textCal.append("<table width='100%' border=0 cellSpacing=0 cellPadding=0><tr>");
				textCal.append("<td class=\"bold\" style='border:0;width:70%' width='70%'>["+getBusyTypeNm( _busy_type)+"]</td>");
				
				if("1".equals(frmd.format(stDt.getTime()))){

					textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "<strong></td>");
				}else{
					textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+ frmd.format(stDt.getTime()) + "<strong></td>");
				}

				textCal.append("</tr></table>");
//				
//				if("1".equals(frmd.format(stDt.getTime()))){
//					textCal.append("	<strong class=\"" + dayFontClass + "\">"
//							+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "</strong>");
//				}else{
//					textCal.append("	<strong class=\"" + dayFontClass + "\">"
//							+ frmd.format(stDt.getTime()) + "</strong>");
//				}

//				textCal.append("	<strong class=\"" + dayFontClass + "\">"
//						+ frmd.format(stDt.getTime()) + "</strong>");
				textCal.append("</div>");

				textCal.append("	<div class=\"" + roomBackClass + "\">");
				textCal.append("		<ul>");
				textCal.append(roomListT.toString());
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;아쿠아</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;캔투스</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;캔투스</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;테라</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;루면</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;케글</a></li>");
				textCal.append("		</ul>");
				textCal.append("	</div>");
				textCal.append("</td>");
				// textCal.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\"#fdfdf6\"");
				// textCal.append("	id=\"day_"+htmlDt+"\">");
				// textCal.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
				// textCal.append("		<tbody>");
				// textCal.append("			<tr>");
				// textCal.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
				// textCal.append("					<font color=\"green\">"+frmd.format(stDt.getTime())+"</font></a></b>");
				// textCal.append("					<span class=\"pm_nm pms\"></span>");
				// textCal.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;\"></span>");
				// textCal.append(tdHtml.toString() );
				// textCal.append("				</td>");
				// textCal.append("			</tr>");
				// textCal.append("		</tbody>");
				// textCal.append("	</table>");
				// textCal.append("</td>");
				// stDt
				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
			}
			// 마무리
			textCal.append("</tr>");
		}

		// 이미지 사이즈 구하기
		String popImg = (String) pensionInfo.get("event_img");
		if (null != popImg && !"".equals(popImg)) {
			String FilePath = req.getSession().getServletContext()
					.getRealPath(popImg);
			File eventImg = new File(FilePath);
			if (eventImg.isFile()) {
				Image img = new ImageIcon(FilePath).getImage();
				mav.addObject("eventW", img.getWidth(null));
				mav.addObject("eventH", img.getHeight(null));
			}
		}

		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("txtCal", textCal.toString());
		// mav.addObject("groupList", groupList);
		mav.addObject("reservation_dt", vo.getReservation_dt());

		// select * from pension_group
		return mav;
	}

	public String getBusyTypeNm(String busy_type) {
		String gl_busy_type = "";
		if ("0101".equals(busy_type)) {
			gl_busy_type = "비수기 주중";
		} else if ("0102".equals(busy_type)) {
			gl_busy_type = "비수기 금요일";
		} else if ("0103".equals(busy_type)) {
			gl_busy_type = "비수기 토요일";
		} else if ("0104".equals(busy_type)) {
			gl_busy_type = "준수기 주중";
		} else if ("0105".equals(busy_type)) {
			gl_busy_type = "준수기 금요일";
		} else if ("0106".equals(busy_type)) {
			gl_busy_type = "준수기 토요일";
		} else if ("0107".equals(busy_type)) {
			gl_busy_type = "성수기 주중";
		} else if ("0108".equals(busy_type)) {
			gl_busy_type = "성수기 금요일";
		} else if ("0109".equals(busy_type)) {
			gl_busy_type = "성수기 토요일";
		} else if ("0110".equals(busy_type)) {
			gl_busy_type = "휴일";
		}
		return gl_busy_type;
	}

	/**
	 * 연박설정화면
	 * 
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc1004Q(@RequestParam Map<String,Object> vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		if ((null == vo.get("p_id") || "".equals(vo.get("p_id")))) {
			mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}


		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");
		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		Calendar d1 = Calendar.getInstance();
		mav.addObject("nDtAll", frmDtAll.format(d1.getTime()));

		if (null == vo.get("reservation_dt") || "".equals(vo.get("reservation_dt"))) {
			vo.put("reservation_dt",frmDate.format(d1.getTime()));
		}
		

		PETIVo petiVo = new PETIVo();
		petiVo.setP_id((String)vo.get("p_id"));
		Map pensionInfo = petiService.peti300Q(petiVo);

		mav.addObject("pensionInfo", pensionInfo);
		
		Calendar todayCalendar = Calendar.getInstance();

		// 입력값에 맞게 세팅
		todayCalendar.set(Calendar.YEAR,
				Integer.parseInt(vo.get("reservation_dt").toString().substring(0, 4)));
		todayCalendar.set(Calendar.MONTH,
				Integer.parseInt(vo.get("reservation_dt").toString().substring(4, 6))-1);
		todayCalendar.set(Calendar.DATE,
				1);

		mav.addObject("yyyy",Integer.parseInt(vo.get("reservation_dt").toString().substring(0, 4)));
		mav.addObject("mm",Integer.parseInt(vo.get("reservation_dt").toString().substring(4, 6)));
		

		int leftBlanks = todayCalendar.get(Calendar.DAY_OF_WEEK)
				- todayCalendar.get(Calendar.DATE) % 7;
		int monthSize = todayCalendar.getActualMaximum(Calendar.DATE);
		int rightBlanks = (7 - (leftBlanks + monthSize) % 7) % 7;

		int iSearchDayTotal = monthSize + rightBlanks;
		
		Calendar todayCalendarTmp = (Calendar) todayCalendar.clone();
		todayCalendarTmp.set(Calendar.DATE, 1);
		List SearchList = new ArrayList<>();
		for(int i =0; i<iSearchDayTotal;i++){
			if(i!=0){
				todayCalendarTmp.add(Calendar.DATE, 1);	
			}
			
			SearchList.add(frmDate.format(todayCalendarTmp.getTime().getTime()));
		}
		vo.put("list", SearchList);
		
		List useList = service.petc1004Q(vo);
//		System.out.println("PEREController.petc1004Q()" + useList);
		
		System.out.println(todayCalendar.get(Calendar.YEAR) + "년 "
				+ (todayCalendar.get(Calendar.MONTH) + 1) + "월");
		System.out.println("일\t월\t화\t수\t목\t금\t토");
//		
		todayCalendarTmp = (Calendar) todayCalendar.clone();
		todayCalendarTmp.set(Calendar.DATE, 1);
		todayCalendarTmp.add(Calendar.DATE, -1);
		// i=1base 가 계산이 편하다.
		StringBuffer sb = new StringBuffer("<tr class=\"tt\">");
		int forMax = leftBlanks + monthSize + rightBlanks;
		forChk=0;
		
		List groups =  petiService.peti501Q(petiVo);
		
		for (int i = 1; i <= forMax; i++) {
			// 날짜 찍기
			if (i <= leftBlanks){
				System.out.print("LL");
				sb.append("<td></td>");
			}
				
			if (leftBlanks < i ){
				System.out.print(i - leftBlanks);
				todayCalendarTmp.add(Calendar.DATE, 1);
				
				
				sb.append("<td class=\"day15\" width=\"10%\" id=\"day_");
				sb.append(frmDate.format(todayCalendarTmp.getTime().getTime()));
				sb.append("\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\"><tbody><tr><td align=\"left\" valign=\"top\" height=\"100\"><b><font color=\"green\">");
				sb.append(frmd.format(todayCalendarTmp.getTime().getTime()));
				sb.append("</font></b><br/>");
				sb.append(getInfo(useList,frmDate.format(todayCalendarTmp.getTime().getTime()),groups));
//				sb.append(frmd.format(todayCalendarTmp.getTime().getTime()));
				sb.append("</td></tr></tbody></table></td>");
			}
//			if (leftBlanks + monthSize < i){
//				System.out.print("RR");
//				todayCalendarTmp.add(Calendar.DATE, 1);
//				sb.append("<td>");
//				sb.append(frmd.format(todayCalendarTmp.getTime().getTime()));
//				sb.append("</td>");
//			}

			System.out.print("\t");
			if (i % 7 == 0){
				sb.append("</tr>");
				if(forMax !=i){
					sb.append("<tr>");	
				}
				
				System.out.println();
			}
		}
//		sb.append("<tr>");
		mav.addObject("calendar",sb.toString());
//		

		return mav;
	}
	private int forChk = 0;
	public String getInfo(List list, String date, List groups){
		StringBuffer sb = new StringBuffer("");

		boolean chk = false;
		for(int i =forChk; i < list.size();i++){
			Map map = (Map) list.get(i);
			if(date.equals(map.get("dt"))){
				if(!chk){
					
					sb.append("<span class=\"divDel groupList \">");
					for(int j= 0 ; j < groups.size();j++ ){
//						sb.append(map.get("dt"));
						Map group = (Map) groups.get(j);
						
						sb.append("<label><input name=\"group_");
						sb.append(group.get("pg_no"));
						sb.append("\" onclick=\"chkedGroup('");
						sb.append(date);
						sb.append("','");
						sb.append(group.get("pg_no"));
						sb.append("',$(this).attr('checked'));\" ");
						sb.append(" type=\"checkbox\" >");
						sb.append(group.get("group_nm"));
						sb.append("</label><br>");
					}
					
					sb.append("</span>");
					sb.append("<span class=\"divDel siteList siteList_");
					sb.append(date);
					sb.append("\" style='display:none;'>");
					chk = true;
				}
				
				sb.append("<label><input name=\"pr_no\" value=\"");
				sb.append(map.get("pr_no"));
				sb.append("\" type=\"checkbox\" class=\"");
				sb.append("pg_no_");
				sb.append(map.get("pg_no"));
				sb.append("\" />");
				sb.append(map.get("room_nm"));
				if(null !=map.get("relay_day") ){
					sb.append( "(" );
					sb.append( map.get("relay_day") );
					sb.append( "박," );
					int pay = (int) map.get("rrr_pay");
					sb.append( pay/1000  );
					sb.append( "천원)" );
				}
				
				sb.append("</label><br>");
				
				forChk = i+1;
			}else{
				if(sb.toString() !=null && !"".equals(sb.toString()) ){
					sb.append("</span>");	
				}
				break;
			}
		}
		if(!"".equals(sb.toString())){
			sb.append("<br/>");
			sb.append("<span>");
			sb.append("연박할인<br>");
			sb.append("1. <select name='rsv_days'><option value='0'>선택하세요</option><option value='2'>2박3일</option><option value='3'>3박4일</option><option value='4'>4박5일</option><option value='5'>5박6일</option><option value='6'>6박7일</option></select>");
			sb.append("</br>2. <input name='rrr_pays' type='text' style='width:50px;text-align: right' />,000 할인");
			sb.append("</br> <a href='#' onclick=\"saveData('");
			sb.append(date);
			sb.append("');return false;\">[ 저장하기 ]</a>");
			sb.append("</span>");
		}
		return sb.toString();
	}
//	@RequestMapping
//	public ModelAndView petc1004Q(PEREVo vo, HttpServletRequest req,
//			HttpServletResponse res) throws Exception {
//
//		isMember(req, res);
//		ModelAndView mav = new ModelAndView();
//		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
//				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
//						.length() > 8)) {
//			mav = new ModelAndView("/common/close");
//			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
//			mav.addObject("historyBackYn", "Y");
//
//			return mav;
//		}
//
//		COMAVo codeVo = new COMAVo();
//
//		PETIVo petiVo = new PETIVo();
//		petiVo.setP_id(vo.getP_id());
//		Map pensionInfo = petiService.peti300Q(petiVo);
//
//		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
//
//		Calendar d1 = Calendar.getInstance();
//		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
//			mav.addObject("reservation_dt", frmDate.format(d1.getTime()));
//		} else {
//			mav.addObject("reservation_dt", vo.getReservation_dt());
//		}
//
//		mav.addObject("groups", petiService.peti501Q(petiVo));
//		mav.addObject("pensionInfo", pensionInfo);
//
//		return mav;
//	}
	
	

	/**
	 * 연박설정(관리자)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@RequestMapping
	public ModelAndView petc1005T(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);
		ModelAndView mav = new ModelAndView();
		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}

		String reservation_dt = vo.getReservation_dt();
		String p_id = vo.getP_id();
		int yyyy = Integer.parseInt(reservation_dt.substring(0, 4));
		int mm = Integer.parseInt(reservation_dt.substring(4, 6)) - 1;
		int dd = Integer.parseInt(reservation_dt.substring(6, 8));
		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		Calendar d1 = Calendar.getInstance();// 오늘

		for (int i = 0; i < vo.getPr_no_cnts().length; i++) {
			int pr_no = (int) vo.getPr_nos()[vo.getPr_no_cnts()[i]];
			int rsv_days = (int) vo.getRsv_days()[vo.getPr_no_cnts()[i]];
			
			int rrr_pay = 0;
			if(!"".equals(vo.getRrr_pays()[vo.getPr_no_cnts()[i]])){
				rrr_pay = Integer.parseInt( vo.getRrr_pays()[vo.getPr_no_cnts()[i]]);
			}

			// 기존데이터 조회 후 삭제
			vo.setPm_dt(reservation_dt);
			vo.setPr_no(pr_no);
			Map searchMap = service.petc1005_1Q(vo);

			if (searchMap != null) {
				int c_pr_no = (int) searchMap.get("pr_no");
				int c_rsv_days = (int) searchMap.get("relay_day");
				String c_reservation_dt = searchMap.get("reservation_dt")
						.toString();
				vo.setReservation_dt(c_reservation_dt);
				List next = new ArrayList();
				d1.set(yyyy, mm, dd);// 지정일.
				for (int j = 0; j < c_rsv_days; j++) {
					if (j != 0) {
						d1.add(Calendar.DATE, 1);
					}

					next.add(frmDate.format(d1.getTime()));
				}
				vo.setNext_dates(next);

				service.petc1005_2T(vo);
			}
//			연박 백업정보 삭제
			Map searchMap1 = service.petc1005_3Q(vo);

			if (searchMap1 != null) {
				int c_pr_no = (int) searchMap1.get("pr_no");
				int c_rsv_days = (int) searchMap1.get("relay_day");
				String c_reservation_dt = searchMap1.get("reservation_dt")
						.toString();
				vo.setReservation_dt(c_reservation_dt);
				List next = new ArrayList();
				d1.set(yyyy, mm, dd);// 지정일.
				for (int j = 0; j < c_rsv_days; j++) {
					if (j != 0) {
						d1.add(Calendar.DATE, 1);
					}

					next.add(frmDate.format(d1.getTime()));
				}
				vo.setNext_dates(next);

				service.petc1005_4T(vo);
			}

			// if(searchMap)

			if (rsv_days > 1) {
				// 기존데이터에 추가

				d1.set(yyyy, mm, dd);// 지정일.
				for (int j = 0; j < rsv_days; j++) {
					if (j == 0) {
						vo.setRelay_state("S");
					} else {
						vo.setRelay_state("E");
					}
					if (j != 0) {
						d1.add(Calendar.DATE, 1);
					}

					vo.setPr_no(pr_no);
					vo.setPm_dt(frmDate.format(d1.getTime()));
					vo.setRelay_day(rsv_days);
					vo.setRrr_pay(rrr_pay);

					service.petc1005T(vo);

				}
			}
		}

		mav.setViewName("/common/close");
		// mav.addObject("redirect","./petc1004Q.do?p_id="+vo.getP_id()+"&reservation_dt="+frmDate.format(d2.getTime()));
		mav.addObject("redirect", "./petc1004Q.do?p_id=" + vo.getP_id());
		mav.addObject("msg", "저장되었습니다");

		return mav;
	}
	
	
	/**
	 * 관리자 화면 예약현황(그룹이 하나일경우)
	 * @param vo
	 * @param req
	 * @param res
	 * @return
	 * @throws Exception
	 */
	@RequestMapping
	public ModelAndView petc1006Q(PEREVo vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		isMember(req, res);

		if ((null == vo.getP_id() || "".equals(vo.getP_id()))
				|| (null != vo.getReservation_dt() && vo.getReservation_dt()
						.length() > 8)) {
			ModelAndView mav = new ModelAndView("/common/close");
			mav.addObject("msg", "접근이 올바르지않습니다 관리자에게 문의하세요");
			mav.addObject("historyBackYn", "Y");

			return mav;
		}
		PETIVo petiVo = new PETIVo();
		petiVo.setP_id(vo.getP_id());
		Map pensionInfo = petiService.peti300Q(petiVo);

		ModelAndView mav = new ModelAndView();
		// if("T".equals(pensionInfo.get("view_type1"))){
		// mav = new ModelAndView("usr/pe/re/petc100_TQ");
		// }else{
		// //이미지 기반 달력
		// mav = new ModelAndView("usr/pe/re/petc100_IQ");
		// }

		SimpleDateFormat frmDate = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat frmMonth = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat frmd = new SimpleDateFormat("d");
		SimpleDateFormat frmDtAll = new SimpleDateFormat("yyyy년 MM월 dd일 (E)");

		Calendar d1 = Calendar.getInstance();
		mav.addObject("nDtAll", frmDtAll.format(d1.getTime()));

		if (null == vo.getReservation_dt() || "".equals(vo.getReservation_dt())) {
			vo.setReservation_dt(frmDate.format(d1.getTime()));
		}

		// 이전달 조회 금지
		// if(chkMonth>chkConditionMonth){
		// vo.setReservation_dt(frmDate.format(d1.getTime()));
		// chkConditionMonth = chkMonth;
		// mav.addObject("msg", "이전달은 예약이 불가능합니다.");
		// }

		Calendar destDate = Calendar.getInstance();

		if (!vo.getReservation_dt().substring(0, 6)
				.equals(frmMonth.format(destDate.getTime()))) {
			destDate.set(
					Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
					Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
					1);
		} else {
			destDate.set(
					Integer.parseInt(vo.getReservation_dt().substring(0, 4)),
					Integer.parseInt(vo.getReservation_dt().substring(4, 6)) - 1,
					Integer.parseInt(vo.getReservation_dt().substring(6, 8)));
		}

		Calendar startDate = (Calendar) destDate.clone();
		destDate.set(Calendar.DATE,
				destDate.getActualMaximum(Calendar.DAY_OF_MONTH));
		// 해당월이 몇주가 나오는지
		int week = destDate.get(Calendar.WEEK_OF_MONTH);

		Calendar lastDate = Calendar.getInstance();

		if ("D".equals(pensionInfo.get("reservation_cal"))) {
			// 일반

			// 해당월에 추가되야할 날수
			int addDate = 7 - destDate.get(Calendar.DAY_OF_WEEK);

			destDate.add(Calendar.DATE, addDate);
			lastDate = (Calendar) destDate.clone();
		} else {
			// 이월

			Calendar nowDt = (Calendar) startDate.clone();
			// 해당월에 추가되야할 날수
			int addDate = 7 - startDate.get(Calendar.DAY_OF_WEEK);
			addDate = addDate + (7 * (week - 1));
			nowDt.add(Calendar.DATE, addDate);
			lastDate = (Calendar) nowDt.clone();
		}
		// frmDate.format(startDate.getTime())
		Calendar addDt = (Calendar) startDate.clone();
		List dateList = new ArrayList();
		long b = (lastDate.getTimeInMillis() - startDate.getTimeInMillis()) / 1000;
		int dateCha = (int) (b / (60 * 60 * 24));
		dateList.add(frmDate.format(addDt.getTime()));
		for (int i = 0; i < dateCha; i++) {
			addDt.add(Calendar.DATE, 1);
			dateList.add(frmDate.format(addDt.getTime()));
		}
		vo.setList(dateList);

		// 객실 목록
		List roomsList = service.pere101Q(vo);

		// 예약현황
		List reservationList = service.petc1003Q(vo);

		StringBuffer textCal = new StringBuffer();
		StringBuffer tdHtml = new StringBuffer();

		int sevenChk = 0;

		if ("D".equals(pensionInfo.get("reservation_cal"))) {
			// 일반
			Calendar stDt = (Calendar) startDate.clone();
			stDt.set(Calendar.DATE, 1);

			textCal.append("<tr>");
			int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
			for (int i = 0; i < addDate; i++) {
				textCal.append("<td></td>");
				sevenChk++;
			}
			// 빈데이터 처리
			int beforeDt = Integer.parseInt(vo.getReservation_dt().substring(6,
					8));
			if (!vo.getReservation_dt().substring(0, 6)
					.equals(frmMonth.format(Calendar.getInstance().getTime()))) {
				beforeDt = 0;
			}
			StringBuffer blankRooms = new StringBuffer();
			for (int i = 0; i < roomsList.size(); i++) {
				blankRooms.append("<li>&nbsp;</li>");
			}
			for (int i = 1; i < beforeDt; i++) {
				sevenChk++;

				textCal.append("<td valign='top'>");

				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}

				textCal.append("<div class=\"tr ");
				textCal.append(dayBackClass);
				textCal.append("\">");

				textCal.append("	<strong class=\"" + dayFontClass + "\">"
						+ frmd.format(stDt.getTime()) + "</strong>");
				textCal.append("</div>");

				textCal.append("	<div class=\"\">");
				textCal.append("		<ul>");
				textCal.append(blankRooms.toString());
				textCal.append("		</ul>");
				textCal.append("	</div>");

				textCal.append("</td>");

				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
			}

			long lDateCha = (lastDate.getTimeInMillis() - startDate
					.getTimeInMillis()) / 1000;
			int forCa = beforeDt + (int) (lDateCha / (60 * 60 * 24));

			int listIndex = 0;
			int listChk = 0;
			// 데이터 있는 자료 처리
			for (int i = beforeDt; i <= forCa; i++) {
				sevenChk++;
				tdHtml.setLength(0);

				String htmlDt = frmDate.format(stDt.getTime());

				for (int ii = 0; ii < roomsList.size(); ii++) {
					int dateNowNum = Integer.parseInt(frmDate.format(stDt
							.getTime()));

					Map proM = null;
					Map room = (Map) roomsList.get(ii);
					for (int j = listIndex; j < reservationList.size(); j++) {
						proM = (Map) reservationList.get(j);
						int dateNum = Integer.parseInt(proM.get(
								"reservation_dt").toString());
						if (dateNum == dateNowNum
								&& room.get("pr_no") == proM.get("pr_no")) {
							listIndex = j;
							break;
						} else {
							proM = null;
						}
					}

					String site_size = "";// room.get("area_p")+""
					if (null != room.get("area_p")
							&& !"".equals(room.get("area_p"))) {
						site_size = "가로 " + room.get("area_p") + "m, 세로 "
								+ room.get("area_m") + "m";
					}

					String room_form = "";
					if (null != room.get("room_form")
							&& !"".equals(room.get("room_form"))) {
						room_form = "" + room.get("room_form");
					}

					if (proM == null) {
						// 요일체크
						int dayOfWeek = stDt.get(Calendar.DAY_OF_WEEK);

						String busy_type = "0101";
						int pm_pay = Integer.parseInt(room.get("busy_1_base")
								.toString()) * 1000;
						if (6 == dayOfWeek) {
							// 금요일
							busy_type = "0102";
							pm_pay = Integer.parseInt(room.get("busy_1_fri")
									.toString()) * 1000;
						} else if (7 == dayOfWeek) {
							// 토요일
							busy_type = "0103";
							pm_pay = Integer.parseInt(room.get("busy_1_sat")
									.toString()) * 1000;
						}

						tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
								+ room.get("p_id")
								+ "&reservation_dt="
								+ dateNowNum
								+ "&pg_no="
								+ room.get("pg_no")
								+ "&sel_pr_no="
								+ room.get("pr_no")
								+ "\" room_nm='"
								+ room.get("room_nm")
								+ "' pm_pay='"
								+ pm_pay
								+ "' reservation_nm='' busy_type_nm='"
								+ getBusyTypeNm(busy_type)
								+ "' rm_status=''  site_size=\""
								+ site_size
								+ "\" site_form=\""
								+ room_form
								+ "\"><img src=\"/camping/img/icon_green.jpg\">&nbsp;"
								+ room.get("room_nm") + "</a></li>");
					} else {
						String img = "icon_green.jpg";
						if ("C".equals(proM.get("rm_status"))) {
							img = "icon_red.jpg";
							tdHtml.append("<li class='liPop'><a class='calRed' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'  site_size=\""
									+ site_size
									+ "\" site_form=\""
									+ room_form
									+ "\"><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;완료["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else if ("R".equals(proM.get("rm_status"))) {
							img = "icon_blue.jpg";
							tdHtml.append("<li class='liPop'><a class='calBlue' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'  site_size=\""
									+ site_size
									+ "\" site_form=\""
									+ room_form
									+ "\"><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;대기["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else {
							tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
									+ room.get("p_id")
									+ "&reservation_dt="
									+ dateNowNum
									+ "&pg_no="
									+ room.get("pg_no")
									+ "&sel_pr_no="
									+ room.get("pr_no")
									+ "\" rm_status='' room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "'  site_size=\""
									+ site_size
									+ "\" site_form=\""
									+ room_form
									+ "\"><img src=\"/camping/img/"
									+ img
									+ "\">&nbsp;"
									+ room.get("room_nm")
									+ "</a></li>");
						}

					}
				}

				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}

				textCal.append("<td class=\"day23\" valign=\"top\" ");
				textCal.append("	id=\"day_" + htmlDt + "\">");

				textCal.append("<div class=\"tr ");
				textCal.append(dayBackClass);
				textCal.append("\">");
				
				if("1".equals(frmd.format(stDt.getTime()))){
					textCal.append("	<strong class=\"" + dayFontClass + "\">"
							+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "</strong>");
				}else{
					textCal.append("	<strong class=\"" + dayFontClass + "\">"
							+ frmd.format(stDt.getTime()) + "</strong>");
				}
				
				textCal.append("</div>");

				textCal.append("	<div class=\"" + roomBackClass + "\">");
				textCal.append("		<ul>");
				textCal.append(tdHtml.toString());

				textCal.append("		</ul>");
				textCal.append("	</div>");
				textCal.append("</td>");

				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
			}
			// 마무리
			textCal.append("</tr>");
		} else {
			// 이월
			Calendar stDt = (Calendar) startDate.clone();
			// stDt.set(Calendar.DATE, 1);
			// frmDate.format(stDt.getTime());
			textCal.append("<tr>");
			int addDate = stDt.get(Calendar.DAY_OF_WEEK) - 1;
			for (int i = 0; i < addDate; i++) {
				textCal.append("<td></td>");
				sevenChk++;
			}
			// 빈데이터 처리
			int beforeDt = Integer.parseInt(vo.getReservation_dt().substring(6,
					8));
			if (!vo.getReservation_dt().substring(0, 6)
					.equals(frmMonth.format(Calendar.getInstance().getTime()))) {
				beforeDt = 0;
			}

			long lDateCha = (lastDate.getTimeInMillis() - startDate
					.getTimeInMillis()) / 1000;
			int forCa = beforeDt + (int) (lDateCha / (60 * 60 * 24));

			int listChk = 0;

			int listIndex = 0;

			// reservationList
			// 데이터 있는 자료 처리
			for (int i = beforeDt; i <= forCa; i++) {
				sevenChk++;
				// tdHtml.setLength(0);
				// icon_green.jpg //신
				// icon_blue.jpg //대
				// icon_red.jpg //완
				String htmlDt = frmDate.format(stDt.getTime());
				tdHtml.setLength(0);
				String _busy_type= "";
				for (int ii = 0; ii < roomsList.size(); ii++) {
					int dateNowNum = Integer.parseInt(frmDate.format(stDt
							.getTime()));

					Map proM = null;
					Map room = (Map) roomsList.get(ii);
					for (int j = listIndex; j < reservationList.size(); j++) {
						proM = (Map) reservationList.get(j);
						int dateNum = Integer.parseInt(proM.get(
								"reservation_dt").toString());
			
						if (dateNum == dateNowNum
								&& 
								Integer.toString((Integer)room.get("pr_no")).equals(
										Integer.toString((Integer)proM.get("pr_no")))
								) {
							listIndex = j;
							break;
						} else {
							proM = null;
						}
					}
					if (proM == null) {
						// 요일체크
						int dayOfWeek = stDt.get(Calendar.DAY_OF_WEEK);

						String busy_type = "0101";
						int pm_pay = Integer.parseInt(room.get("busy_1_base")
								.toString()) * 1000;
						if (6 == dayOfWeek) {
							// 금요일
							busy_type = "0102";
							pm_pay = Integer.parseInt(room.get("busy_1_fri")
									.toString()) * 1000;
						} else if (7 == dayOfWeek) {
							// 토요일
							busy_type = "0103";
							pm_pay = Integer.parseInt(room.get("busy_1_sat")
									.toString()) * 1000;
						}

						tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
								+ room.get("p_id")
								+ "&reservation_dt="
								+ dateNowNum
								+ "&pg_no="
								+ room.get("pg_no")
								+ "&sel_pr_no="
								+ room.get("pr_no")
								+ "\" room_nm='"
								+ room.get("room_nm")
								+ "' pm_pay='"
								+ pm_pay
								+ "' reservation_nm='' busy_type_nm='"
								+ getBusyTypeNm(busy_type)
								+ "' rm_status=''><img src=\"/camping/img/icon_green.jpg\">&nbsp;"
								+ room.get("room_nm") + "</a></li>");
					} else {
						_busy_type=proM.get("busy_type").toString();
						String img = "icon_green.jpg";
						if ("C".equals(proM.get("rm_status"))) {
							img = "icon_red.jpg";
							tdHtml.append("<li class='liPop'><a class='calRed' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;완료["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else if ("R".equals(proM.get("rm_status"))) {
							img = "icon_blue.jpg";
							tdHtml.append("<li class='liPop'><a class='calBlue' href=\"#\" onclick=\"alert('예약 불가능합니다');\" room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' reservation_nm='"
									+ proM.get("reservation_nm")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "' rm_status='"
									+ proM.get("rm_status")
									+ "'><img src=\"/camping/img/"
									+ img
									+ "\" pm_pay='"
									+ proM.get("pm_pay")
									+ "'>&nbsp;대기["
									+ room.get("room_nm")
									+ "]</a></li>");
						} else {
							tdHtml.append("<li class='liPop'><a href=\"./petc0101Q.do?p_id="
									+ room.get("p_id")
									+ "&reservation_dt="
									+ dateNowNum
									+ "&pg_no="
									+ room.get("pg_no")
									+ "&sel_pr_no="
									+ room.get("pr_no")
									+ "\" rm_status='' room_nm='"
									+ room.get("room_nm")
									+ "' pm_pay='"
									+ proM.get("pm_pay")
									+ "' busy_type_nm='"
									+ getBusyTypeNm((String) proM
											.get("busy_type"))
									+ "'><img src=\"/camping/img/"
									+ img
									+ "\">&nbsp;"
									+ room.get("room_nm")
									+ "</a></li>");
						}

					}
				}

				int dow = stDt.get(Calendar.DAY_OF_WEEK);

				// 일 백그라운드
				String dayBackClass = "calJuganBack";
				String dayFontClass = "";
				// 객실 백그라운드
				String roomBackClass = "";

				if (dow == 7) {// 토요일
					dayBackClass = "calJuganBackSat";
					dayFontClass = "calBlue";
					roomBackClass = "calBackSat";
				} else if (dow == 1) {// 일요일
					dayBackClass = "calJuganBackSun";
					dayFontClass = "calRed";
					roomBackClass = "calBackSun";
				}
				if(dow == 6){
					if("".equals(_busy_type)){_busy_type="0102";}	
				}else if(dow == 7){
					if("".equals(_busy_type)){_busy_type="0103";}
				}else{
					if("".equals(_busy_type)){_busy_type="0101";}
				}

				textCal.append("<td class=\"day23\" valign=\"top\" ");
				textCal.append("	id=\"day_" + htmlDt + "\">");

				textCal.append("<div class=\"");
				textCal.append(dayBackClass);
				textCal.append("\">");

				textCal.append("<table width='100%' border=0 cellSpacing=0 cellPadding=0><tr>");
				textCal.append("<td class=\"bold\" style='border:0;width:70%' width='70%'>["+getBusyTypeNm( _busy_type)+"]</td>");
				
				if("1".equals(frmd.format(stDt.getTime()))){

					textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "<strong></td>");
				}else{
					textCal.append("<td class=\"tr\" style=\"border:0;\"><strong class=\""+dayFontClass+"\">"+ frmd.format(stDt.getTime()) + "<strong></td>");
				}

				textCal.append("</tr></table>");

				
//				if("1".equals(frmd.format(stDt.getTime()))){
//					textCal.append("	<strong class=\"" + dayFontClass + "\">"
//							+(stDt.get(Calendar.MONTH)+1) +"."+ frmd.format(stDt.getTime()) + "</strong>");
//				}else{
//					textCal.append("	<strong class=\"" + dayFontClass + "\">"
//							+ frmd.format(stDt.getTime()) + "</strong>");
//				}
//
//				textCal.append("	<strong class=\"" + dayFontClass + "\">"
//						+ frmd.format(stDt.getTime()) + "</strong>");
				textCal.append("</div>");

				textCal.append("	<div class=\"" + roomBackClass + "\">");
				textCal.append("		<ul>");
				textCal.append(tdHtml.toString());
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;아쿠아</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;캔투스</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;캔투스</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;테라</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;루면</a></li>");
				// textCal.append("			<li><a href=\"\"><img src=\"/camping/img/icon_blue.jpg\">&nbsp;케글</a></li>");
				textCal.append("		</ul>");
				textCal.append("	</div>");
				textCal.append("</td>");
				// textCal.append("<td class=\"day23\" width=\"14%\" valign=\"top\" bgcolor=\"#fdfdf6\"");
				// textCal.append("	id=\"day_"+htmlDt+"\">");
				// textCal.append("	<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">");
				// textCal.append("		<tbody>");
				// textCal.append("			<tr>");
				// textCal.append("				<td align=\"left\" valign=\"top\" height=\"100\"><b><a href=\"#\">");
				// textCal.append("					<font color=\"green\">"+frmd.format(stDt.getTime())+"</font></a></b>");
				// textCal.append("					<span class=\"pm_nm pms\"></span>");
				// textCal.append("					<span class=\"pm_dc pms\" style=\"color: red; text-align: center; position: relative; float: left; width: 100%; clear: both;\"></span>");
				// textCal.append(tdHtml.toString() );
				// textCal.append("				</td>");
				// textCal.append("			</tr>");
				// textCal.append("		</tbody>");
				// textCal.append("	</table>");
				// textCal.append("</td>");
				// stDt
				stDt.add(Calendar.DATE, 1);
				if (sevenChk % 7 == 0) {
					textCal.append("</tr>");
					textCal.append("<tr>");
				}
			}
			// 마무리
			textCal.append("</tr>");
		}

		// 이미지 사이즈 구하기
		String popImg = (String) pensionInfo.get("event_img");
		if (null != popImg && !"".equals(popImg)) {
			String FilePath = req.getSession().getServletContext()
					.getRealPath(popImg);
			File eventImg = new File(FilePath);
			if (eventImg.isFile()) {
				Image img = new ImageIcon(FilePath).getImage();
				mav.addObject("eventW", img.getWidth(null));
				mav.addObject("eventH", img.getHeight(null));
			}
		}

		mav.addObject("pensionInfo", pensionInfo);
		mav.addObject("txtCal", textCal.toString());
		// mav.addObject("groupList", groupList);
		mav.addObject("reservation_dt", vo.getReservation_dt());

		// select * from pension_group
		return mav;
	}
	
	
	@RequestMapping
	public ModelAndView getUsrInfo(@RequestParam Map vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		ModelAndView mav = new ModelAndView("common/toJson");

		String smsChk = (String) req.getSession().getAttribute("smsChk");

		List list = service.getUsrInfo(vo);
		
		
		Map jsonMap = new HashMap();
		
		Map map = new HashMap();
		
		map.put("list", list);
		JSONObject json = new JSONObject(map);
		jsonMap.put("data", AESSecurity.encrypt(json.toString()));
		
		
		mav.addObject("map", jsonMap);
		return mav;
	}
	
	@RequestMapping
	public ModelAndView main(@RequestParam Map vo, HttpServletRequest req,
			HttpServletResponse res) throws Exception {

		ModelAndView mav = new ModelAndView();

		
		mav.addObject("map", "");
		return mav;
	}
}
